Link to home
Start Free TrialLog in
Avatar of Fionageo
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!
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

>>At the moment when I assign the selected time to the JDataChooser modifies the Year to 2001 and I dont want that.

How are you doing that? Please post code
Avatar of Fionageo
Fionageo

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());
         }
       };
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
>>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?
jCal is private JDateChooser jCal = null;

but how can I extract the time from the private JSpinner timeSpinner?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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