This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

1 SpinnerDateModel with 3 spinners?

 
Mark Dary
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

I want something like the following to show the same date in 3 different spinners so I can spin through days or months or years:



But this dosen't seem to work, can anyone help?

Thanks.

Mark.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you're after a DatePicker, use JCalendar

http://www.toedter.com/
 
Mark Dary
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Michael

Unfortunately I also need hours, minutes and seconds but I gave an example with just 3 spinners (instead of six).

My main query is how to ensure each one uses (and updates itself) with the same datemodel?

Any ideas?

Mark.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> My main query is how to ensure each one uses (and updates itself) with the same datemodel?

the problem is going to be when the spinner increment/decrement buttons are clicked.
there is no calendar field associated with the model, so the display could end up anything,
if the model doesn't know the field.

it's easy enough to set up with individual models, but the problem is you probably want
the following model adjusted if a maximum is reached/incremented
e.g. display is 31 May, click increment button for 31, it will go to 1
when this happens you probably want May to also 'click-over' to Jun

if so, you may have to build your own action for this, which would involve
setting your own UI for each spinner, to access the creatNext/PreviousButton()'s
remove the actionListeners from those buttons
add your own actionListener, where you
1) create a calendar object from the current display of your 6 spinners (ensuring setLenient is true - default value)
2) add/decrement '1' to the calendar field associated with the button clicked
3) setting each spinner's value to the new calendar date via calendar.get(whateverField)

you now have to work out how you want to handle end of month
e.g. display is 31 May, and you increment the month
1 is added to month --> 31 June --> which becomes 1 July (with lenient true)
or, 30 Apr + 1 month = 30 May (or do you want 31 May)
and then there's February, 31 Jan+1 month = 31 Feb = 3 Mar (or 2 Mar for leap year)
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in case the above makes little sense, run this
(just found out 31 Jan+1 month = 28 Feb, thought it used to go to 3 Mar)



 
Mark Dary
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much for this Michael

I will have a play with it.

Thanks again.

Mark.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic