javax.swing.text
public class DefaultFormatter extends JFormattedTextField.AbstractFormatter implements Cloneable, Serializable
DefaultFormatter is a concrete formatter for use in
{@link JFormattedTextField}s.
It can format arbitrary values by invoking
their {@link Object#toString} method.
In order to convert a String back to
a value, the value class must provide a single argument constructor that
takes a String object as argument value. If no such constructor is found,
the String itself is passed back by #stringToValue.
| Constructor Summary | |
|---|---|
| DefaultFormatter()
Creates a new instance of DefaultFormatter. | |
| Method Summary | |
|---|---|
| Object | clone()
Creates and returns a clone of this DefaultFormatter.
|
| boolean | getAllowsInvalid()
Returns whether or not invalid edits are allowed or not. |
| boolean | getCommitsOnValidEdit()
Returns true if the value should be committed after
each valid modification of the input field, false if
it should never be committed by this formatter.
|
| protected DocumentFilter | getDocumentFilter()
Returns the DocumentFilter that is used to restrict input.
|
| boolean | getOverwriteMode()
Returns the value of the overwriteMode property.
|
| Class<?> | getValueClass()
Returns the class that is used for values. |
| void | install(JFormattedTextField ftf)
Installs the formatter on the specified {@link JFormattedTextField}.
|
| void | setAllowsInvalid(boolean allowsInvalid)
Sets the value of the allowsInvalid property.
|
| void | setCommitsOnValidEdit(boolean commitsOnValidEdit)
Sets the value of the commitsOnValidEdit property.
|
| void | setOverwriteMode(boolean overwriteMode)
Sets the value of the overwriteMode property.
|
| void | setValueClass(Class<?> valueClass)
Sets the class that is used for values.
|
| Object | stringToValue(String string)
Converts a String (from the JFormattedTextField input) to a value.
|
| String | valueToString(Object value)
Converts a value object into a String. |
DefaultFormatter.Returns: a clone of this object
Throws: CloneNotSupportedException not thrown here
Returns: the value of the allowsInvalid property
true if the value should be committed after
each valid modification of the input field, false if
it should never be committed by this formatter.
Returns: the state of the commitsOnValidEdit property
See Also: DefaultFormatter
Returns: the DocumentFilter that is used to restrict input
overwriteMode property.
If that is set to true then newly inserted characters
overwrite existing values, otherwise the characters are inserted like
normal. The default is true.
Returns: the value of the overwriteMode property
Returns: the class that is used for values
JFormattedTextFieldJTextField
Parameters: ftf the {@link JFormattedTextField} in which this formatter is installed
allowsInvalid property.
Parameters: allowsInvalid the new value for the property
See Also: getAllowsInvalid
commitsOnValidEdit property.
Parameters: commitsOnValidEdit the new state of the
commitsOnValidEdit property
See Also: DefaultFormatter
overwriteMode property.
If that is set to true then newly inserted characters
overwrite existing values, otherwise the characters are inserted like
normal. The default is true.
Parameters: overwriteMode the new value for the overwriteMode
property
Parameters: valueClass the class that is used for values
See Also: getValueClass
Parameters: string the string to convert
Returns: the value for the string
Throws: ParseException if the string cannot be converted into a value object (e.g. invalid input)
Parameters: value the value to be converted
Returns: the string representation of the value
Throws: ParseException if the value cannot be converted