• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1037
  • Last Modified:

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!
0
Fionageo
Asked:
Fionageo
  • 4
  • 3
2 Solutions
 
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
 
CEHJCommented:
>>cal.setTime

You call that twice. The second call will overwrite the first
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 
CEHJCommented:
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

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now