aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Reading out JSpinner Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Reading out JSpinner" Watch "Reading out JSpinner" New topic
Author

Reading out JSpinner

Constanze Michaelis
Greenhorn

Joined: Jul 28, 2004
Posts: 28
Hi @ all!

I am writing an applet where I use JSpinners to get user entries. now I don't know how to read them out into an integer variable.

thanks in advance
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
This question would probably be more appropriate in the GUI forum. However, I'll still try to answer it here. If you look at the API docs for JSpinner, you will see that it has a getValue() method to return the current value. This method returns an Object, but you can cast it to the type that you expect. If you are using SpinnerNumberModel in the JSpinner, then you can cast this Object from JSpinner.getValue() to an Integer. From there, you can get an int from the Integer object using its intValue() method.

With that said, I strongly suggest that you familiarize yourself with the Java API docs. Although I had a vague idea how to answer your question, I still had to use the API docs to look up the details of the above description. They are an invaluable tool when you are programming Java as it is nearly impossible to memorize every method in every class that is available in the standard API.

Keep Coding!

Layne


Java API Documentation
The Java Tutorial
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Moving this to the Swing / AWT / SWT / JFace forum...


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
sasi kala
Ranch Hand

Joined: Dec 17, 2004
Posts: 68
use ChageListener // javax.swing.event.ChangeListener


class .. implements ChageListener
{
......
jSpinner1.addChangeListener(this);
.........

public void stateChanged(javax.swing.event.ChangeEvent evt)
{
Integer i = new Integer(jSpinner1.getValue().toString());
int value = i.intValue();
......
}

}

All The Best
Constanze Michaelis
Greenhorn

Joined: Jul 28, 2004
Posts: 28
thanks for your reply, but i got it by myself before

bye
Constanze
 
 
subject: Reading out JSpinner