• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cannot pull data out of a spinner(s)

 
Mark Owen Kelly
Greenhorn
Posts: 3
Java Mac OS X Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:


 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mark Owen Kelly
Greenhorn
Posts: 3
Java Mac OS X Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vibhatha Lakmal
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this simple app...
You can get the values in the JSpinner quiet easily...



I hope this would help you.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your single Listener class is not at all good design. You ought to use a different class for each action.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic