Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSpinner DateModel : Set a date

 
leliel
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
how is it possible to set a GregorianCalendar in a JSpinner or JSpinnerDateModel?
thanks
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
here is how I did it:
(the spinner shows only the year: 'yyyy').

cheers
Chantal
 
leliel
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks! all works fine.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic