• 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

Cannot pull data out of a spinner(s)

 
Greenhorn
Posts: 3
Mac OS X Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:


 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac OS X Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic