سؤال

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