• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

spinner double trouble

 
Ranch Hand
Posts: 201
2
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, ranchers!

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 ....

Kind regards,
Robert Ingmarsson.



 
Bartender
Posts: 732
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Robert Ingmarsson
Ranch Hand
Posts: 201
2
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI!

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.

//robert.

 
reply
    Bookmark Topic Watch Topic
  • New Topic