Como incrementar a partir da segunda casa após a virgula ao invés de 1 em 1 em um JSpinner.
Ex.: 1,98 - 1,99 - 2,00 - 2,01 …
Como incrementar a partir da segunda casa após a virgula ao invés de 1 em 1 em um JSpinner.
Ex.: 1,98 - 1,99 - 2,00 - 2,01 …
E aí, blz ?
Então, não conheço muito de Swing não, mas dei uma breve pesquisada e encontrei uma maneira:
public static void main(String[] args)
{
double min = 0.00;
double valor = 0.70;
double max = 1.00;
double incremento = 0.01;
SpinnerNumberModel model = new SpinnerNumberModel(valor, min, max, incremento);
JSpinner spinner = new JSpinner(model);
JSpinner.NumberEditor editor = (JSpinner.NumberEditor)spinner.getEditor();
DecimalFormat format = editor.getFormat();
format.setMinimumFractionDigits(2);
Dimension d = spinner.getPreferredSize();
d.setSize(85, d.getHeight());
spinner.setPreferredSize(d);
JPanel panel = new JPanel();
panel.add(spinner);
JFrame f = new JFrame();
f.add(panel);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLocationRelativeTo(null);
f.setSize(240,100);
f.setVisible(true);
}