public class javax.swing.text
DefaultFormatter


Show All Login
Java SE 6
  
Extends: JFormattedTextField.AbstractFormatter
Implements: Cloneable, Serializable
Extended by: InternationalFormatter, MaskFormatter
Details
DefaultFormatter formats aribtrary objects. Formatting is done by invoking the toString method. In order to convert the value back to a String, your class must provide a constructor that takes a String argument. If no single argument constructor that takes a String is found, the returned value will be the String passed into stringToValue.

Instances of DefaultFormatter can not be used in multiple instances of JFormattedTextField. To obtain a copy of an already configured DefaultFormatter, use the clone method.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see java.beans.XMLEncoder.
version1.14 11/17/05
since1.4
See also javax.swing.JFormattedTextField.AbstractFormatter


Constructors
public DefaultFormatter()
Creates a DefaultFormatter.

Methods
public Object clone() throws CloneNotSupportedException Details
Creates a copy of the DefaultFormatter.
returncopy of the DefaultFormatter
public void install(JFormattedTextField ftf) Details
Installs the DefaultFormatter 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.
ftfJFormattedTextField to format for, may be null indicating uninstall from current JFormattedTextField.

public Object stringToValue(String string) throws ParseException Details
Converts the passed in String into an instance of getValueClass by way of the constructor that takes a String argument. If getValueClass returns null, the Class of the current value in the JFormattedTextField will be used. If this is null, a String will be returned. If the constructor thows an exception, a ParseException will be thrown. If there is no single argument String constructor, string will be returned.
ThrowsParseException: if there is an error in the conversion
stringString to convert
returnObject representation of text
public String valueToString(Object value) throws ParseException Details
Converts the passed in Object into a String by way of the toString method.
ThrowsParseException: if there is an error in the conversion
valueValue to convert
returnString representation of value

Properties
public void setAllowsInvalid(boolean allowsInvalid) Details
Sets whether or not the value being edited is allowed to be invalid for a length of time (that is, stringToValue throws a ParseException). It is often convenient to allow the user to temporarily input an invalid value.
allowsInvalidUsed to indicate if the edited value must always be valid
public boolean getAllowsInvalid() Details
Returns whether or not the value being edited is allowed to be invalid for a length of time.
returnfalse if the edited value must always be valid
public void setCommitsOnValidEdit(boolean commit) Details
Sets when edits are published back to the JFormattedTextField. If true, commitEdit is invoked after every valid edit (any time the text is edited). On the other hand, if this is false than the DefaultFormatter does not publish edits back to the JFormattedTextField. As such, the only time the value of the JFormattedTextField will change is when commitEdit is invoked on JFormattedTextField, typically when enter is pressed or focus leaves the JFormattedTextField.
commitUsed to indicate when edits are commited back to the JTextComponent
public boolean getCommitsOnValidEdit() Details
Returns when edits are published back to the JFormattedTextField.
returntrue if edits are commited after evey valid edit
protected DocumentFilter getDocumentFilter() Details
Returns the DocumentFilter used to restrict the characters that can be input into the JFormattedTextField.
returnDocumentFilter to restrict edits
protected NavigationFilter getNavigationFilter() Details
Returns the NavigationFilter used to restrict where the cursor can be placed.
returnNavigationFilter to restrict navigation
public void setOverwriteMode(boolean overwriteMode) Details
Configures the behavior when inserting characters. If overwriteMode is true (the default), new characters overwrite existing characters in the model.
overwriteModeIndicates if overwrite or overstrike mode is used
public boolean getOverwriteMode() Details
Returns the behavior when inserting characters.
returntrue if newly inserted characters overwrite existing characters
public void setValueClass(Class valueClass) Details
Sets that class that is used to create new Objects. If the passed in class does not have a single argument constructor that takes a String, String values will be used.
valueClassClass used to construct return value from stringToValue
public Class getValueClass() Details
Returns that class that is used to create new Objects.
returnClass used to constuct return value from stringToValue