Fionageo
asked on
How to parse selected time of JSpinner to JDateChooser?
Hello:
I have a JDateChooser and a JSpinner, the user must select the date and the time, what I am trying to do is to get the selected time of the object JSpinner and I want to assing it to the JDateChooser, so at the end I have the date and time selected by the user in one object.
At the moment when I assign the selected time to the JDataChooser modifies the Year to 2001 and I dont want that.
Any idea how can I fix it?
Thanks a lot!
I have a JDateChooser and a JSpinner, the user must select the date and the time, what I am trying to do is to get the selected time of the object JSpinner and I want to assing it to the JDateChooser, so at the end I have the date and time selected by the user in one object.
At the moment when I assign the selected time to the JDataChooser modifies the Year to 2001 and I dont want that.
Any idea how can I fix it?
Thanks a lot!
ASKER
Here it is:
ChangeListener listener = new ChangeListener() {
public void stateChanged(ChangeEvent evt) {
JSpinner spinner = (JSpinner)evt.getSource();
SpinnerModel dateModel = spinner.getModel();
// Get the new value
Object value = spinner.getValue();
// System.out.println("Source : " + );
Calendar cal = jCal.getCalendar();
cal.setTime((Date)(spinner .getValue( )));
cal.setTime(jCal.getDate() );
// cal.set
System.out.println("Source : " + cal.toString());
}
};
ChangeListener listener = new ChangeListener() {
public void stateChanged(ChangeEvent evt) {
JSpinner spinner = (JSpinner)evt.getSource();
SpinnerModel dateModel = spinner.getModel();
// Get the new value
Object value = spinner.getValue();
// System.out.println("Source
Calendar cal = jCal.getCalendar();
cal.setTime((Date)(spinner
cal.setTime(jCal.getDate()
// cal.set
System.out.println("Source
}
};
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes, but when I do this
Calendar cal = jCal.getCalendar();
cal.setTime((Date)(spinner .getValue( )));
changes me the date to 01.01 2001 and in the jCal the current date is 20.04.2009. This changes not only the time but also the date.
Calendar cal = jCal.getCalendar();
cal.setTime((Date)(spinner
changes me the date to 01.01 2001 and in the jCal the current date is 20.04.2009. This changes not only the time but also the date.
>>This changes not only the time but also the date.
Yes. To Java, the date and time are the same thing. You would need to extract the time part and simply set the time fields. What is 'jCal' btw - a widget?
Yes. To Java, the date and time are the same thing. You would need to extract the time part and simply set the time fields. What is 'jCal' btw - a widget?
ASKER
jCal is private JDateChooser jCal = null;
but how can I extract the time from the private JSpinner timeSpinner?
but how can I extract the time from the private JSpinner timeSpinner?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Not sure I follow, why do you have both a JSpinner and a JDateChooser?
Do the two just need to share the same model, that way they would get updated automatically for you
Do the two just need to share the same model, that way they would get updated automatically for you
How are you doing that? Please post code