简体   繁体   中英

How to set date picker initial value?

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?

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);

This should solve it:

UtilDateModel model = new UtilDateModel();
model.setDate( 2014, 8, 24 );
startDatePicker = new JDatePickerImpl(
    new JDatePanelImpl( model ), new DateLabelFormatter() );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM