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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top