|
Préférences
Moteurs de recherche
|
||||||||||||||||||||||||||||||||||||||
JavaTM 2 Platform Std. Ed. v1.5.0
javax.swing.text
|
Constructor Summary | |
---|---|
DefaultFormatter()
Creates a DefaultFormatter. |
Method Summary | |
---|---|
Object |
clone()
Creates a copy of the DefaultFormatter. |
boolean |
getAllowsInvalid()
Returns whether or not the value being edited is allowed to be invalid for a length of time. |
boolean |
getCommitsOnValidEdit()
Returns when edits are published back to the JFormattedTextField . |
protected DocumentFilter |
getDocumentFilter()
Returns the DocumentFilter used to restrict the characters
that can be input into the JFormattedTextField . |
protected NavigationFilter |
getNavigationFilter()
Returns the NavigationFilter used to restrict where the
cursor can be placed. |
boolean |
getOverwriteMode()
Returns the behavior when inserting characters. |
Class<?> |
getValueClass()
Returns that class that is used to create new Objects. |
void |
install(JFormattedTextField ftf)
Installs the DefaultFormatter onto a particular
JFormattedTextField . |
void |
setAllowsInvalid(boolean allowsInvalid)
Sets whether or not the value being edited is allowed to be invalid for a length of time (that is, stringToValue throws
a ParseException ). |
void |
setCommitsOnValidEdit(boolean commit)
Sets when edits are published back to the JFormattedTextField . |
void |
setOverwriteMode(boolean overwriteMode)
Configures the behavior when inserting characters. |
void |
setValueClass(Class<?> valueClass)
Sets that class that is used to create new Objects. |
Object |
stringToValue(String string)
Converts the passed in String into an instance of getValueClass by way of the constructor that
takes a String argument. |
String |
valueToString(Object value)
Converts the passed in Object into a String by way of the toString method. |
Methods inherited from class javax.swing.JFormattedTextField.AbstractFormatter |
---|
getActions, getFormattedTextField, invalidEdit, setEditValid, uninstall |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DefaultFormatter()
Method Detail |
---|
public void install(JFormattedTextField ftf)
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 Action
s 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.
install
in class JFormattedTextField.AbstractFormatter
ftf
- JFormattedTextField to format for, may be null indicating
uninstall from current JFormattedTextField.public void setCommitsOnValidEdit(boolean commit)
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
.
commit
- Used to indicate when edits are commited back to the
JTextComponentpublic boolean getCommitsOnValidEdit()
JFormattedTextField
.
public void setOverwriteMode(boolean overwriteMode)
overwriteMode
is true (the default), new characters
overwrite existing characters in the model.
overwriteMode
- Indicates if overwrite or overstrike mode is usedpublic boolean getOverwriteMode()
public void setAllowsInvalid(boolean allowsInvalid)
stringToValue
throws
a ParseException
).
It is often convenient to allow the user to temporarily input an
invalid value.
allowsInvalid
- Used to indicate if the edited value must always
be validpublic boolean getAllowsInvalid()
public void setValueClass(Class<?> valueClass)
valueClass
- Class used to construct return value from
stringToValuepublic Class<?> getValueClass()
public Object stringToValue(String string) throws ParseException
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.
stringToValue
in class JFormattedTextField.AbstractFormatter
string
- String to convert
ParseException
- if there is an error in the conversionpublic String valueToString(Object value) throws ParseException
toString
method.
valueToString
in class JFormattedTextField.AbstractFormatter
value
- Value to convert
ParseException
- if there is an error in the conversionprotected DocumentFilter getDocumentFilter()
DocumentFilter
used to restrict the characters
that can be input into the JFormattedTextField
.
getDocumentFilter
in class JFormattedTextField.AbstractFormatter
protected NavigationFilter getNavigationFilter()
NavigationFilter
used to restrict where the
cursor can be placed.
getNavigationFilter
in class JFormattedTextField.AbstractFormatter
public Object clone() throws CloneNotSupportedException
clone
in class JFormattedTextField.AbstractFormatter
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.Cloneable