File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JSpinner DateModel : Set a date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JSpinner DateModel : Set a date" Watch "JSpinner DateModel : Set a date" New topic
Author

JSpinner DateModel : Set a date

leliel
Greenhorn

Joined: Mar 25, 2003
Posts: 11
Hi,
how is it possible to set a GregorianCalendar in a JSpinner or JSpinnerDateModel?
thanks
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
hi,
here is how I did it:
(the spinner shows only the year: 'yyyy').

cheers
Chantal
leliel
Greenhorn

Joined: Mar 25, 2003
Posts: 11
Hi,
thanks for your reply.
I've done it this way:

My only problem now are the values, added by the ValueUp and ValueDown button.
I want to increase by 15 Minutes on ValueUp button click, vice versa decrease by 15 Minutes on ValueDown.
What kind of listener do I have to add? Without listener, the value is in-/decreased by one hour.
thanks
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
hi,
I would not use listeners for implementing data logic. do that inside the SpinnerModel. you will have to extend the SpinnerDateModel. overwrite the methods getNextValue() and getPreviousValue() to return the time in 15 minutes steps.
Chantal
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
to be more specific:

as these methods are called quite often it seems quite an overhead to create Calendar objects inside of them.
a (faster) way (but not as "nice"):
- add th 15 minutes as milliseconds to the date value:

or:
reimplement the whole SpinnerDateModel based on GregorianCalendar, not Date.
cheers
Chantal
leliel
Greenhorn

Joined: Mar 25, 2003
Posts: 11
thanks! all works fine.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSpinner DateModel : Set a date