public class DefaultFormatter extends JFormattedTextField.AbstractFormatter implements Cloneable, Serializable
DefaultFormatter
is a concrete formatter for use in
JFormattedTextField
s.
It can format arbitrary values by invoking
their 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 and Description |
---|
DefaultFormatter()
Creates a new instance of
DefaultFormatter . |
Modifier and Type | Method and Description |
---|---|
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
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.
|
getActions, getFormattedTextField, getNavigationFilter, invalidEdit, setEditValid, uninstall
public DefaultFormatter()
DefaultFormatter
.public void install(JFormattedTextField ftf)
JFormattedTextField
.
This method does the following things:
JFormattedTextField
JTextField
install
in class JFormattedTextField.AbstractFormatter
ftf
- the JFormattedTextField
in which this formatter
is installedpublic boolean getCommitsOnValidEdit()
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.commitsOnValidEdit
propertysetCommitsOnValidEdit(boolean)
public void setCommitsOnValidEdit(boolean commitsOnValidEdit)
commitsOnValidEdit
property.commitsOnValidEdit
- the new state of the
commitsOnValidEdit
propertygetCommitsOnValidEdit()
public boolean getOverwriteMode()
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
.overwriteMode
propertypublic void setOverwriteMode(boolean overwriteMode)
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
.overwriteMode
- the new value for the overwriteMode
propertypublic boolean getAllowsInvalid()
public void setAllowsInvalid(boolean allowsInvalid)
allowsInvalid
property.allowsInvalid
- the new value for the propertygetAllowsInvalid()
public Class<?> getValueClass()
public void setValueClass(Class<?> valueClass)
valueClass
- the class that is used for valuesgetValueClass()
public Object stringToValue(String string) throws ParseException
stringToValue
in class JFormattedTextField.AbstractFormatter
string
- the string to convertParseException
- if the string cannot be converted into
a value object (e.g. invalid input)public String valueToString(Object value) throws ParseException
Object.toString()
method on the value.valueToString
in class JFormattedTextField.AbstractFormatter
value
- the value to be convertedParseException
- if the value cannot be convertedpublic Object clone() throws CloneNotSupportedException
clone
in class JFormattedTextField.AbstractFormatter
CloneNotSupportedException
- not thrown hereCloneable
protected DocumentFilter getDocumentFilter()
getDocumentFilter
in class JFormattedTextField.AbstractFormatter