2

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.

ballBreaker
  • 722
  • 1
  • 10
  • 29
Harshali
  • 281
  • 4
  • 9
  • 17

3 Answers3

6

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())
Markus
  • 2,071
  • 4
  • 22
  • 44
Adarsha
  • 69
  • 2
1

If dateChooser is your instanceof JDateChooser:

dateChooser.setDate(new Date());

Edit: I'm not sure what you meen by "set todays date". I assumed you meant set the date in the JDateChooser to todays date (that's what my code does). If it is not what you want, please clarify your question.

Burkhard
  • 14,596
  • 22
  • 87
  • 108
0
((JTextField)dateChooser.getDateEditor().getUiComponent()).setText("");
dateChooser.setDate(new Date());
amal
  • 3,470
  • 10
  • 29
  • 43