aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Cannot pull data out of a spinner(s) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Cannot pull data out of a spinner(s)" Watch "Cannot pull data out of a spinner(s)" New topic
Author

Cannot pull data out of a spinner(s)

Mark Owen Kelly
Greenhorn

Joined: Apr 06, 2012
Posts: 3

Hello: In trying to create a small example JSpinner class I can't for the life of me figure out how to pull data from the spinners. the closest I've gotten is the attached code. Any directional help is appreciated.

From Oracle site I pulled in this code:



When executed and I press the OK button the INFORMATION Dialog prints a lot of stuff but,
I do not see the values anywhere in the list of data that does get returned.
I would like just the selected value of each spinner. Hour Minute AM or PM...

Entire code:



Java Newbie
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

In future, please UseCodeTags <-- link I've added them for you this time.

I can't see why you're jumping through hoops trying to get the current value of a spinner. Have you read the API for JSpinner? It has a method that directly returns what you're going to so much trouble for.

When executed and I press the OK button the INFORMATION Dialog prints a lot of stuff but,
I do not see the values anywhere in the list of data that does get returned.

What elements are you concatenating to form the message for the option pane to display? Concatenating any object with a String uses the output of the object's toString() method. There's no magic that will extract a formatted text field's text and use that instead.


luck, db
There are no new questions, but there may be new answers.
Mark Owen Kelly
Greenhorn

Joined: Apr 06, 2012
Posts: 3

Thanks Darryl,

I'll remember to use the UseCodeTags this time. I was only using the "JFormatteTextField" method as
I could not get the "int getValue" method to work, got invalid type message.

Got it to work after working more with the API. My JAVA All-in-one for Dummies, Oracle's Java The
Complete Reference Eight Edition and my Head First Java books fell short in giving me a example of how
to pull data from a JSpinner.

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

Mark Owen Kelly wrote:I could not get the "int getValue" method to work, got invalid type message.

getValue() returns Object. You would need to cast that to Integer (which can then be auto unboxed to int).

One of my recent gripes about the Java API is that they've made JList and JComboBox generic, but not JSpinner. It would be much easier if you could have a JSpinner<Integer>, and its getValue() method would return an Integer because of the generic type.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Vibhatha Lakmal
Greenhorn

Joined: Aug 29, 2012
Posts: 4
Try this simple app...
You can get the values in the JSpinner quiet easily...



I hope this would help you.


all I care is learn something from everyone...
"If there is a day, I could live, Single breath,I could take I take all the things into ma head "--edited Laid to Rest-Lamb of God...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
Your single Listener class is not at all good design. You ought to use a different class for each action.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cannot pull data out of a spinner(s)
 
Similar Threads
Unable to use JSpinner properly.
Prevent editing of a JSpinner's text box
JSpinner - How to initialize to the top of list
jspinner background color
Non compilation of Sun Java's program SpinnerDemo3