I have a major problem that is causing me a very exotic headache. I have a SpinnerNumberModel that consists of the following
double values as shown below this line ...
I want the values in my spinners editor field to change from 0.0 to 10.0 and back when the user presses the up or down key.
I have registered an ActionMap and InputMap to the editorfield in my spinner. It is in an actionevent method that i try to
control the number selection. Everything works fine but when the value decreases to 0.0, the minimum value in the model,
it always ends up as 0.1 in the editors textfield when i press the down arrow key.
This is where everything fails ...
Can anyone help me out? How do you format that double instance so it displays as 0.0 when the minimum value in the model is
selected. In System.out.println the result looks like the following:
I hope someone can see what i am trying to say. That double variable in the actionevent method never matches the minimum value in the
SpinnerNumberModel that should be 0.0. Have anyone encountered this before? I know i can skip the actionevent method totally and use
default listening. But i just want this solved or as best see what goes wrong. Apologies. My grammar is not so good just like my math ....
Post by:Fred Kleinschmidt
Your problem is that the computer cannot exactly represent the step value of 0.1, so you will probably never be able to reach 0.0 exactly by subtracting 0.1 from the previous value (as you see in your prints, none of the numbers are exactly 0.1 increments).
Post by:Rob Camick
I don't know why you are using custom Actions.
The up/down arrow keys are already bound to Action of the JSpinner. Use the default Actions.
I don't have a problem when I use the default behaviour of a JSpinner.
Post your SSCCE the uses the default behaviour of a JSpinner.
Post by:Robert Ingmarsson
I used the default actions in the spinner and set up a default value of 0.0 by using some work with document event
in the editor field of the spinner class. Sorry for the late reply. The machines aren't that smart as we like to think
they are ... thanks for the answers in this post. This subject is now completed.
This thread has been viewed 516 times.
All times above are in ranch (not your local) time.
The current ranch time is Dec 13, 2018 20:20:05.