*
The moose likes Swing / AWT / SWT and the fly likes 1 SpinnerDateModel with 3 spinners? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "1 SpinnerDateModel with 3 spinners?" Watch "1 SpinnerDateModel with 3 spinners?" New topic
Author

1 SpinnerDateModel with 3 spinners?

Mark Dary
Greenhorn

Joined: Jan 16, 2009
Posts: 29
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

Joined: Jun 09, 2003
Posts: 4632
if you're after a DatePicker, use JCalendar

http://www.toedter.com/
Mark Dary
Greenhorn

Joined: Jan 16, 2009
Posts: 29
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

Joined: Jun 09, 2003
Posts: 4632
> 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

Joined: Jun 09, 2003
Posts: 4632
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

Joined: Jan 16, 2009
Posts: 29
Thanks very much for this Michael

I will have a play with it.

Thanks again.

Mark.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 1 SpinnerDateModel with 3 spinners?
 
Similar Threads
JSpinner.DateEditor - Set default focus on dd
JSpinner with dates
[question]how to "extract" day,month,year,min,second from selected SpinnerDateModel
SpinnerDateModel
Date validation?