Mega Code Archive

 
Categories / Java Tutorial / Swing
 

JFormattedTextField focus lost behaviour

For a JFormattedTextField, the validation is controlled by the focusLostBehavior property. This can be set to one of four values: COMMIT_OR_REVERT: This is the default. When the component loses focus, the component automatically calls the commitEdit() method. This will parse the component's contents and throw a ParseException on error, reverting the contents to the most recent valid value. COMMIT: This setting is similar to COMMIT_OR_REVERT, but it leaves the invalid contents within the field, allowing the user to modify the setting. REVERT: This setting always reverts the value. PERSIST: This setting does nothing. You should manually call commitEdit() yourself to see if the contents are valid before using the contents.