This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Help please, using a JSpinner but I can't get the user's input into a date object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Help please, using a JSpinner but I can Watch "Help please, using a JSpinner but I can New topic
Author

Help please, using a JSpinner but I can't get the user's input into a date object

Sebastion Hill
Ranch Hand

Joined: Jul 10, 2009
Posts: 48
So I have my GUI set up to allow a user to pick a date using the JSpinner with the following code:


I have this as an inner class for when the user presses a button after entering in the date info he/she wants. This is just a test right now, but I can't find a way to get the date on the JSpinner into one easy date object. Do I need to use the spinner and turn it into a string, then parse the string? Or is there an easier, more efficient method, that I am overlooking? :-(

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

Just use getValue() and cast it to Date. JSpinner's getValue() method simply returns getModel().getValue(); for SpinnerDateModel, both getValue() and getDate() return the same value.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Sebastion Hill
Ranch Hand

Joined: Jul 10, 2009
Posts: 48
Rob you are a wonderful person! :-) works!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

Sebastion Hill wrote:Rob you are a wonderful person!

Well duh
 
Don't get me started about those stupid light bulbs.
 
subject: Help please, using a JSpinner but I can't get the user's input into a date object
 
Similar Threads
Just finished my first GUI program (a planner application) ... could you give me feedback?
Non compilation of Sun Java's program SpinnerDemo3
completely lost in terms of trying to understand Collections.synchronizedList
could someone look at my code and help me with a JScrollPane in a JTextPane please?
Jspinner Date increment