aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Finding and using the Jspinner SpinnerNumberModel value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Finding and using the Jspinner SpinnerNumberModel value" Watch "Finding and using the Jspinner SpinnerNumberModel value" New topic
Author

Finding and using the Jspinner SpinnerNumberModel value

David Pountney
Greenhorn

Joined: May 26, 2011
Posts: 27
Hello,

I've got a Jspinner that uses the SpinnerNumberModel and goes from 0 to 30 with an incressement of 1.

I want to be able to have a changeListener method to find and compare the value.

For example, if the user spins the spinner to show the value "3" , then I can do checks on that value to see if it is greater then another value e.g.

So far, I have;



I have a feeling I should be trying to convert the string into an int, but I'm not sure.

So far, I can only think of using the getValue() method, but when I run the code I get nothing. However if I remove the "if (amount1.getValue() == "1") {" line I get some form of output.

Any ideas would be appreciated

Thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

1) Never ever use == to compare Strings, use .equals

2) The actual value returned by SpinnerNumberModel is not a String but a Number, usually a Double or Integer. In your case it's probably Integer. Compare that:
Note that I used Number instead of Integer. This will allow your code to continue working if you start using Long, Double, Float, Short, etc. All of these allow you to retrieve the value as an int using intValue().


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2169
    
    7
Read the JSpinner API and follow the link to the section in the Swing tutorial on "How to Use Spinners" where you will find a demo that uses a ChangeListener on a spinner with a DateSpinnerModel. I'm sure your code would be similiar except you are using a number model.
David Pountney
Greenhorn

Joined: May 26, 2011
Posts: 27
Thank you for your replys

I'll keep those tips in mind from now on

I managed to fix it and get it working, cheers a lot guys!

(I am trying to learn this, not just use you guys to make the code for me, I do spend an hour or so trying to fiqure out what you've told me to do and what it's doing)

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Finding and using the Jspinner SpinnerNumberModel value