I’m using Eclipse to write a java application. My application includes a DateTime widget (org.eclipse.swt.widgets.datetime). I cannot figure out the proper way to assign a default value. I have a DateTime value of 2/1/2012. I’m using the Calendar object to try to set the default value and I guess I just don’t fully understand how it works.
I’ve tried
Calendar.getInstance().setTime(startDate);
StartDateWidget.setDate(Calendar.YEAR, Calendar.MONTH,Calendar.DATE);
This just shows the current date.
And I’ve tried
Calendar startCal = Calendar.getInstance();
startCal.setTime(startDate);
StartDateWidget.setDate(startCal.YEAR, startCal.MONTH, startCal.DATE);
This shows an error in Eclipse about using static accessors and when I run the application, the date shows 3/5/2012.
I’ve check over the internet and see plenty of examples on using the DateTime widget, but I can’t find any examples of setting the default value from an existing datetime value. What am I doing wrong?
You’re using Calendar incorrectly, you need something like:
and similarly for the time.
Calendar.YEAR is just a symbolic value that you can hand to
get()andset(). See the Calendar javadoc