- java.lang.Object
-
- javax.swing.JFormattedTextField.AbstractFormatter
-
- All Implemented Interfaces:
- Serializable
- Direct Known Subclasses:
- DefaultFormatter
- Enclosing class:
- JFormattedTextField
public abstract static class JFormattedTextField.AbstractFormatter extends Object implements Serializable
Instances ofAbstractFormatter
are used byJFormattedTextField
to handle the conversion both from an Object to a String, and back from a String to an Object.AbstractFormatter
s can also enfore editing policies, or navigation policies, or manipulate theJFormattedTextField
in any way it sees fit to enforce the desired policy.An
AbstractFormatter
can only be active in oneJFormattedTextField
at a time.JFormattedTextField
invokesinstall
when it is ready to use it followed byuninstall
when done. Subclasses that wish to install additional state should overrideinstall
and message super appropriately.Subclasses must override the conversion methods
stringToValue
andvalueToString
. Optionally they can overridegetActions
,getNavigationFilter
andgetDocumentFilter
to restrict theJFormattedTextField
in a particular way.Subclasses that allow the
JFormattedTextField
to be in a temporarily invalid state should invokesetEditValid
at the appropriate times.- Since:
- 1.4
-
-
Constructor Summary
Constructors Constructor and Description JFormattedTextField.AbstractFormatter()
-
Method Summary
Methods Modifier and Type Method and Description protected Object
clone()
Clones theAbstractFormatter
.protected Action[]
getActions()
Subclass and override if you wish to provide a custom set ofAction
s.protected DocumentFilter
getDocumentFilter()
Subclass and override if you wish to provide aDocumentFilter
to restrict what can be input.protected JFormattedTextField
getFormattedTextField()
Returns the currentJFormattedTextField
theAbstractFormatter
is 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(JFormattedTextField ftf)
Installs theAbstractFormatter
onto a particularJFormattedTextField
.protected void
invalidEdit()
This should be invoked when the user types an invalid character.protected void
setEditValid(boolean valid)
Invoke this to update theeditValid
property of theJFormattedTextField
.abstract Object
stringToValue(String text)
Parsestext
returning an arbitrary Object.void
uninstall()
Uninstalls any state theAbstractFormatter
may have installed on theJFormattedTextField
.abstract String
valueToString(Object value)
Returns the string value to display forvalue
.
-
-
-
Constructor Detail
-
JFormattedTextField.AbstractFormatter
public JFormattedTextField.AbstractFormatter()
-
-
Method Detail
-
install
public void install(JFormattedTextField ftf)
Installs theAbstractFormatter
onto a particularJFormattedTextField
. This will invokevalueToString
to convert the current value from theJFormattedTextField
to a String. This will then install theAction
s fromgetActions
, theDocumentFilter
returned fromgetDocumentFilter
and theNavigationFilter
returned fromgetNavigationFilter
onto theJFormattedTextField
.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 theJFormattedTextField
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 subclassingJFormattedTextField
and installing/uninstallingAbstractFormatter
at a different time thanJFormattedTextField
does.- Parameters:
ftf
- JFormattedTextField to format for, may be null indicating uninstall from current JFormattedTextField.
-
uninstall
public void uninstall()
Uninstalls any state theAbstractFormatter
may have installed on theJFormattedTextField
. This resets theDocumentFilter
,NavigationFilter
and additionalAction
s installed on theJFormattedTextField
.
-
stringToValue
public abstract Object stringToValue(String text) throws ParseException
Parsestext
returning an arbitrary Object. Some formatters may return null.- Parameters:
text
- String to convert- Returns:
- Object representation of text
- Throws:
ParseException
- if there is an error in the conversion
-
valueToString
public abstract String valueToString(Object value) throws ParseException
Returns the string value to display forvalue
.- Parameters:
value
- Value to convert- Returns:
- String representation of value
- Throws:
ParseException
- if there is an error in the conversion
-
getFormattedTextField
protected JFormattedTextField getFormattedTextField()
Returns the currentJFormattedTextField
theAbstractFormatter
is installed on.- Returns:
- JFormattedTextField formatting for.
-
invalidEdit
protected void invalidEdit()
This should be invoked when the user types an invalid character. This forwards the call to the current JFormattedTextField.
-
setEditValid
protected void setEditValid(boolean valid)
Invoke this to update theeditValid
property of theJFormattedTextField
. If you an enforce a policy such that theJFormattedTextField
is always in a valid state, you will never need to invoke this.- Parameters:
valid
- Valid state of the JFormattedTextField
-
getActions
protected Action[] getActions()
Subclass and override if you wish to provide a custom set ofAction
s.install
will install these on theJFormattedTextField
'sActionMap
.- Returns:
- Array of Actions to install on JFormattedTextField
-
getDocumentFilter
protected DocumentFilter getDocumentFilter()
Subclass and override if you wish to provide aDocumentFilter
to restrict what can be input.install
will install the returned value onto theJFormattedTextField
.- Returns:
- DocumentFilter to restrict edits
-
getNavigationFilter
protected NavigationFilter getNavigationFilter()
Subclass and override if you wish to provide a filter to restrict where the user can navigate to.install
will install the returned value onto theJFormattedTextField
.- Returns:
- NavigationFilter to restrict navigation
-
clone
protected Object clone() throws CloneNotSupportedException
Clones theAbstractFormatter
. The returned instance is not associated with aJFormattedTextField
.- Overrides:
clone
in classObject
- Returns:
- Copy of the AbstractFormatter
- Throws:
CloneNotSupportedException
- if the object's class does not support theCloneable
interface. Subclasses that override theclone
method can also throw this exception to indicate that an instance cannot be cloned.- See Also:
Cloneable
-
-
Traduction non disponible
Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Version en cache
22/12/2024 10:25:59 Cette version de la page est en cache (à la date du 22/12/2024 10:25:59) afin d'accélérer le traitement. Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la dernère version de la page.Document créé le 07/12/2006, dernière modification le 04/03/2020
Source du document imprimé : https://www.gaudry.be/java-api-rf-javax/swing/JFormattedTextField.AbstractFormatter.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.