Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top