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!
FionageoAsked:
Who is Participating?
 
CEHJConnect With a Mentor Commented:
>>cal.setTime

You call that twice. The second call will overwrite the first
0
 
CEHJCommented:
>>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
0
 
FionageoAuthor Commented:
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());
         }
       };
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
FionageoAuthor Commented:
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.
0
 
CEHJCommented:
>>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?
0
 
FionageoAuthor Commented:
jCal is private JDateChooser jCal = null;

but how can I extract the time from the private JSpinner timeSpinner?
0
 
CEHJConnect With a Mentor Commented:
e.g. (You might need an additional Calendar to set with the date first)


int hour = cal.get(Calendar.HOUR_OF_DAY);
int mins = cal.get(Calendar.MINUTES);

Open in new window

0
 
objectsCommented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.