SerializableDefaultFormatterJFormattedTextFieldpublic abstract static class JFormattedTextField.AbstractFormatter extends Object implements Serializable
AbstractFormatter are used by JFormattedTextField to handle the conversion both from an Object to a String, and back from a String to an Object. AbstractFormatters can also enforce editing policies, or navigation policies, or manipulate the JFormattedTextField in any way it sees fit to enforce the desired policy.  An AbstractFormatter can only be active in one JFormattedTextField at a time. JFormattedTextField invokes install when it is ready to use it followed by uninstall when done. Subclasses that wish to install additional state should override install and message super appropriately. 
 Subclasses must override the conversion methods stringToValue and valueToString. Optionally they can override getActions, getNavigationFilter and getDocumentFilter to restrict the JFormattedTextField in a particular way. 
 Subclasses that allow the JFormattedTextField to be in a temporarily invalid state should invoke setEditValid at the appropriate times.
| Modifier | Constructor | Description | 
|---|---|---|
| protected  | Constructor for subclasses to call. | 
| Modifier and Type | Method | Description | 
|---|---|---|
| protected Object | clone() | Clones the  AbstractFormatter. | 
| protected Action[] | getActions() | Subclass and override if you wish to provide a custom set of  Actions. | 
| protected DocumentFilter | getDocumentFilter() | Subclass and override if you wish to provide a  DocumentFilterto restrict what can be input. | 
| protected JFormattedTextField | getFormattedTextField() | Returns the current  JFormattedTextFieldtheAbstractFormatteris installed on. | 
| protected NavigationFilter | getNavigationFilter() | Subclass and override if you wish to provide a filter to restrict where the user can navigate to. | 
| void | install | Installs the  AbstractFormatteronto a particularJFormattedTextField. | 
| protected void | invalidEdit() | This should be invoked when the user types an invalid character. | 
| protected void | setEditValid | Invoke this to update the  editValidproperty of theJFormattedTextField. | 
| abstract Object | stringToValue | Parses  textreturning an arbitrary Object. | 
| void | uninstall() | Uninstalls any state the  AbstractFormattermay have installed on theJFormattedTextField. | 
| abstract String | valueToString | Returns the string value to display for  value. | 
protected AbstractFormatter()
public void install(JFormattedTextField ftf)
AbstractFormatter onto a particular JFormattedTextField. This will invoke valueToString to convert the current value from the JFormattedTextField to a String. This will then install the Actions from getActions, the DocumentFilter returned from getDocumentFilter and the NavigationFilter returned from getNavigationFilter onto the JFormattedTextField.  Subclasses will typically only need to override this if they wish to install additional listeners on the JFormattedTextField. 
 If there is a ParseException in converting the current value to a String, this will set the text to an empty String, and mark the JFormattedTextField as being in an invalid state. 
 While this is a public method, this is typically only useful for subclassers of JFormattedTextField. JFormattedTextField will invoke this method at the appropriate times when the value changes, or its internal state changes. You will only need to invoke this yourself if you are subclassing JFormattedTextField and installing/uninstalling AbstractFormatter at a different time than JFormattedTextField does.
ftf - JFormattedTextField to format for, may be null indicating uninstall from current JFormattedTextField.public void uninstall()
AbstractFormatter may have installed on the JFormattedTextField. This resets the DocumentFilter, NavigationFilter and additional Actions installed on the JFormattedTextField.public abstract Object stringToValue(String text) throws ParseException
text returning an arbitrary Object. Some formatters may return null.text - String to convertParseException - if there is an error in the conversionpublic abstract String valueToString(Object value) throws ParseException
value.value - Value to convertParseException - if there is an error in the conversionprotected JFormattedTextField getFormattedTextField()
JFormattedTextField the AbstractFormatter is installed on.protected void invalidEdit()
protected void setEditValid(boolean valid)
editValid property of the JFormattedTextField. If you an enforce a policy such that the JFormattedTextField is always in a valid state, you will never need to invoke this.valid - Valid state of the JFormattedTextFieldprotected Action[] getActions()
Actions. install will install these on the JFormattedTextField's ActionMap.protected DocumentFilter getDocumentFilter()
DocumentFilter to restrict what can be input. install will install the returned value onto the JFormattedTextField.null.protected Object clone() throws CloneNotSupportedException
AbstractFormatter. The returned instance is not associated with a JFormattedTextField.clone in class Object
CloneNotSupportedException - if the object's class does not support the Cloneable interface. Subclasses that override the clone method can also throw this exception to indicate that an instance cannot be cloned.
    © 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
    https://docs.oracle.com/en/java/javase/21/docs/api/java.desktop/javax/swing/JFormattedTextField.AbstractFormatter.html