how to clear JDateChooser field?

Harshali picture Harshali · Jul 30, 2012 · Viewed 31.2k times · Source

I am using a JDateChooser as a component in a JForm. I have setup a JButton, which resets all of the fields on this form to blank. I do not have issues with the actionListener, or the method for clearing, but instead am unsure how to clear the JDateChooser component.

More specifically I am wondering how to clear the Date from the JTextField component of the date chooser, such that it is blank.

Furthermore, I would like to set this field to the current date after it is cleared.

Answer

Adarsha picture Adarsha · Sep 10, 2012

If you want to clear the JDateChooser field:

JDateChooser dateChooser = new JDateChooser();
dateChooser.setCalendar(null);

This code will set the field to null.

To set the date to today you can use for example:

dateChooser.setDate(new Date())