Originally posted by ram shyam:
I have a JTextfield(with a default value) on which I am doing some validation of the text entered in it. Once the validation is done, I throw appropriate error message using Joptionpanes. After closing the pop-up, the text field should get reset to the original data set in it and not the invalid data. In my case, the textfield contains the invalid data.
Since I am using documentListener and focusListener (to invoke actions based on the data entered), once the data is entered on the field, the text value of the field changes and hence I lose the original data.
Please let me know if there is any existing API for resetting and if not, how can this be achieved.
Is there a reason you need to use a JTextField instead of a JFormattedTextField?
A JFormattedTextField maintains both its current text and its last valid
value, which is what you seem to want. (Of course it also does validation and data reversion.)