• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSpinner & SpinnerNumberModel

David Garratt
Ranch Hand
Posts: 213
Eclipse IDE Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JSpinner on my form which I have setup to display 3 decimal places which works ok. However if the user enters more than 3 decimal places and exits the input field the value is rounded and the 4th, 5th decimals truncated - or so it appears on screen. However when I use .getValue.toString() on the spinner it returns the original value with all the decimal places entered by the user, which is confusing for me and the user. What's the best way to overcome this. I have considered somehow stopping the input of the extra decimals or maybe truncating the value without rounding/hiding the extra digits.

I've run out of cunning ideas. The code I have for displaying the JSpinner looks like this :-

SpinnerNumberModel model = new SpinnerNumberModel((double) 0, (double) 0.000, (double) 999999.999, (double) 1.000);
jSpinnerQuantity = new JSpinner(model);
JSpinner.NumberEditor editor = (JSpinner.NumberEditor)jSpinnerQuantity.getEditor();
DecimalFormat format = editor.getFormat();
jSpinnerQuantity.setBounds(322, 21, 98, 21);
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic