Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java datePicker - How to set default date in JTextfield

Im using a DatePicker as part of a form. What i would like is for todays date to be in the JTexfield thats with the JDatePicker when the form opens.

If i use :

            UtilDateModel model = new UtilDateModel();
    model.setDate(2014, 06, 06);
    JDatePanelImpl datePanel = new JDatePanelImpl(model);
    JDatePickerImpl datePicker = new JDatePickerImpl(datePanel);

All it does is set the date in the popup box. What i need it to do is be on the form as soon as it opens

I want it to be like this when its first opened.

enter image description here

But its like this

enter image description here

Found the answer.

Ue the method

model.setSelected(true);

After setting the initial time.

like image 315
user237462 Avatar asked Dec 15 '25 13:12

user237462


1 Answers

Use the method

model.setSelected(true);

After setting the initial time.

like image 187
user237462 Avatar answered Dec 18 '25 11:12

user237462



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!