1

I have a date_picker from toedter.com from jcalendar package which are swing components. How can I set an initial value to it? I'm using netbeans.

I added the date_picker on design view and tried this on my source code :

UtilDateModel model = new UtilDateModel();
model.setDate(2014, 8, 24);
model.setSelected(true);

but I've been playing around where to put it still doesn't seem to work.

Any idea guys?

impulse
  • 206
  • 2
  • 15
  • I think you have to use setValue() http://www.gwtproject.org/javadoc/latest/com/google/gwt/user/datepicker/client/DatePicker.html#setValue(java.util.Date) to set it... – StackFlowed Oct 06 '14 at 14:19
  • What kind of date picker are you talking about? At least indicate the package name in your question or the technology (like gwt, swing etc.). This should also be reflected in the added tags. – icza Oct 06 '14 at 14:24
  • What you tried appears to be correct and sufficient. The bug might be elsewhere in your code. Try to post an [MCVE](http://stackoverflow.com/help/mcve). – icza Oct 06 '14 at 14:39
  • I'll just use the alternative JSpinner since user we'll just change the date. Thanks for the help! – impulse Oct 06 '14 at 14:45

2 Answers2

3

You can try this out :

String dateValue = "initial date value";  // must be in (yyyy- mm- dd ) format
Date date = new SimpleDateFormat("yyyy-mm-dd").parse(dateValue);
jDateChooser.setDate(date);
Jeshen Appanna
  • 480
  • 4
  • 16
0

This should solve it:

UtilDateModel model = new UtilDateModel();
model.setDate( 2014, 8, 24 );
startDatePicker = new JDatePickerImpl(
    new JDatePanelImpl( model ), new DateLabelFormatter() );
J. Wang
  • 81
  • 1
  • 5