简体   繁体   中英

How to clear the JXDatePicker field

I am developing a simple desktop application with Java and NetBeans 7 I have a textfield and a textarea as well as a jxdatepicker I have a CLEAR button that is suppose to clear the fields when needed

I use the

jtextfield.setText("") and 
  jtextArea.setText("")

to clear the textfield and textarea as indicated. but my problem is that how do I clear the date picker to present a clean field when the clear button is clicked?

basically:

picker.setDate(null);

Addendum:

digging into the internals of the picker and setting the text of its editor is wrong because the text is only updated in the editor but not committed to the underlying model:

picker.getEditor().setText("");
System.out.println(picker.getDate());

// output
Thu Feb 28 00:00:00 CET 2013 

// output after nulling the date with the appropriate api
null

1.Set property like this. datePicker.getModel().setValue(null);;

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