DefaultFormatter formats arbitrary 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 JavaBeans
has been added to the java.beans package.
Please see java..
javax.swing.JFormattedTextField.AbstractFormatter
| Modifier and Type | Class and Description |
|---|---|
| private class | DefaultFormatter.
DocumentFilter implementation that calls back to the replace method of DefaultFormatter. |
| private class | DefaultFormatter.
NavigationFilter implementation that calls back to methods with same name in DefaultFormatter. |
| pack-priv static class | DefaultFormatter.
ReplaceHolder is used to track where insert/remove/replace is going to happen. |
| Modifier and Type | Field and Description |
|---|---|
| private boolean | allowsInvalid
Indicates if the value being edited must match the mask. |
| private boolean | commitOnEdit
If true, any time a valid edit happens commitEdit is invoked. |
| private DocumentFilter | documentFilter
DocumentFilter that forwards calls back to DefaultFormatter. |
| private NavigationFilter | navigationFilter
NavigationFilter that forwards calls back to DefaultFormatter. |
| private boolean | overwriteMode
If true, overwrite mode is enabled. |
| pack-priv transient DefaultFormatter. | replaceHolder
Used during replace to track the region to replace. |
| private Class | valueClass
Class used to create new instances. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv boolean | canReplace(DefaultFormatter.
Returns true if the edit described by |
| public Object | Returns: copy of the DefaultFormatterOverrides javax. Creates a copy of the DefaultFormatter. |
| pack-priv void | |
| public boolean | Returns: false if the edited value must always be validReturns whether or not the value being edited is allowed to be invalid for a length of time. |
| public boolean | Returns: true if edits are committed after every valid editReturns when edits are published back to the
|
| protected DocumentFilter | Returns: DocumentFilter to restrict editsOverrides javax. Returns the |
| pack-priv int | |
| protected NavigationFilter | Returns: NavigationFilter to restrict navigationOverrides javax. Returns the |
| pack-priv int | getNextCursorPosition(int offset, int direction)
Returns the next cursor position from offset by incrementing
|
| private int | getNextNavigatableChar(int offset, int direction)
Returns the next editable character starting at offset incrementing
the offset by |
| pack-priv int | getNextVisualPositionFrom(JTextComponent text, int pos, Position.
Finds the next navigable character. |
| public boolean | Returns: true if newly inserted characters overwrite existing charactersReturns the behavior when inserting characters. |
| pack-priv DefaultFormatter. | getReplaceHolder(DocumentFilter.
Returns the ReplaceHolder to track the replace of the specified text. |
| pack-priv String | getReplaceString(int offset, int deleteLength, String replaceString)
A convenience methods to return the result of deleting
|
| public Class | Returns: Class used to construct return value from stringToValueReturns that class that is used to create new Objects. |
| public void | install(JFormattedTextField
JFormattedTextField to format for, may be null indicating
uninstall from current JFormattedTextField. ftf)Overrides javax. Installs the |
| pack-priv boolean | |
| pack-priv boolean | isNavigatable(int offset)
Subclasses should override this if they want cursor navigation to skip certain characters. |
| pack-priv boolean | |
| pack-priv void | moveDot(NavigationFilter.
NavigationFilter method, subclasses that wish finer control should override this. |
| pack-priv void | |
| pack-priv void | replace(DocumentFilter.
DocumentFilter method, funnels into |
| pack-priv boolean | replace(DefaultFormatter.
If the edit described by |
| pack-priv void | |
| public void | setAllowsInvalid(boolean
Used to indicate if the edited value must always
be valid allowsInvalid)Sets whether or not the value being edited is allowed to be invalid
for a length of time (that is, |
| public void | setCommitsOnValidEdit(boolean
Used to indicate when edits are committed back to the
JTextComponent commit)Sets when edits are published back to the
|
| pack-priv void | setDot(NavigationFilter.
NavigationFilter method, subclasses that wish finer control should override this. |
| public void | setOverwriteMode(boolean
Indicates if overwrite mode is used overwriteMode)Configures the behavior when inserting characters. |
| public void | setValueClass(Class<?>
Class used to construct return value from
stringToValue valueClass)Sets that class that is used to create new Objects. |
| public Object | Returns: Object representation of textString to convert string)Implements abstract javax. Converts the passed in String into an instance of
|
| pack-priv void | updateValue()
Pushes the value to the JFormattedTextField if the current value
is valid and invokes |
| pack-priv void | |
| public String | Returns: String representation of valueValue to convert value)Implements abstract javax. Converts the passed in Object into a String by way of the
|
| allowsInvalid | back to summary |
|---|---|
| private boolean allowsInvalid Indicates if the value being edited must match the mask. | |
| commitOnEdit | back to summary |
|---|---|
| private boolean commitOnEdit If true, any time a valid edit happens commitEdit is invoked. | |
| documentFilter | back to summary |
|---|---|
| private DocumentFilter documentFilter DocumentFilter that forwards calls back to DefaultFormatter. | |
| navigationFilter | back to summary |
|---|---|
| private NavigationFilter navigationFilter NavigationFilter that forwards calls back to DefaultFormatter. | |
| overwriteMode | back to summary |
|---|---|
| private boolean overwriteMode If true, overwrite mode is enabled. | |
| replaceHolder | back to summary |
|---|---|
| pack-priv transient DefaultFormatter. Used during replace to track the region to replace. | |
| valueClass | back to summary |
|---|---|
| private Class<?> valueClass Class used to create new instances. | |
| DefaultFormatter | back to summary |
|---|---|
| public DefaultFormatter() Creates a DefaultFormatter. | |
| canReplace | back to summary |
|---|---|
| pack-priv boolean canReplace(DefaultFormatter. Returns true if the edit described by | |
| clone | back to summary |
|---|---|
| public Object clone() throws CloneNotSupportedException Overrides javax. Creates a copy of the DefaultFormatter.
| |
| commitEdit | back to summary |
|---|---|
| pack-priv void commitEdit() throws ParseException Invokes | |
| getAllowsInvalid | back to summary |
|---|---|
| public boolean getAllowsInvalid() Returns whether or not the value being edited is allowed to be invalid for a length of time.
| |
| getCommitsOnValidEdit | back to summary |
|---|---|
| public boolean getCommitsOnValidEdit() Returns when edits are published back to the
| |
| getDocumentFilter | back to summary |
|---|---|
| protected DocumentFilter getDocumentFilter() Overrides javax. Returns the
| |
| getInitialVisualPosition | back to summary |
|---|---|
| pack-priv int getInitialVisualPosition() Returns the initial location to position the cursor at. This forwards
the call to | |
| getNavigationFilter | back to summary |
|---|---|
| protected NavigationFilter getNavigationFilter() Overrides javax. Returns the
| |
| getNextCursorPosition | back to summary |
|---|---|
| pack-priv int getNextCursorPosition(int offset, int direction) Returns the next cursor position from offset by incrementing
| |
| getNextNavigatableChar | back to summary |
|---|---|
| private int getNextNavigatableChar(int offset, int direction) Returns the next editable character starting at offset incrementing
the offset by | |
| getNextVisualPositionFrom | back to summary |
|---|---|
| pack-priv int getNextVisualPositionFrom(JTextComponent text, int pos, Position. Finds the next navigable character. | |
| getOverwriteMode | back to summary |
|---|---|
| public boolean getOverwriteMode() Returns the behavior when inserting characters.
| |
| getReplaceHolder | back to summary |
|---|---|
| pack-priv DefaultFormatter. Returns the ReplaceHolder to track the replace of the specified text. | |
| getReplaceString | back to summary |
|---|---|
| pack-priv String getReplaceString(int offset, int deleteLength, String replaceString) A convenience methods to return the result of deleting
| |
| getValueClass | back to summary |
|---|---|
| public Class Returns that class that is used to create new Objects.
| |
| install | back to summary |
|---|---|
| public void install(JFormattedTextField ftf) Overrides javax. Installs the
Subclasses will typically only need to override this if they
wish to install additional listeners on the
If there is a
While this is a public method, this is typically only useful
for subclassers of
| |
| isLegalInsertText | back to summary |
|---|---|
| pack-priv boolean isLegalInsertText(String text) Returns true if the text in | |
| isNavigatable | back to summary |
|---|---|
| pack-priv boolean isNavigatable(int offset) Subclasses should override this if they want cursor navigation
to skip certain characters. A return value of false indicates
the character at | |
| isValidEdit | back to summary |
|---|---|
| pack-priv boolean isValidEdit(DefaultFormatter. | |
| moveDot | back to summary |
|---|---|
| pack-priv void moveDot(NavigationFilter. NavigationFilter method, subclasses that wish finer control should override this. | |
| positionCursorAtInitialLocation | back to summary |
|---|---|
| pack-priv void positionCursorAtInitialLocation() Positions the cursor at the initial location. | |
| replace | back to summary |
|---|---|
| pack-priv void replace(DocumentFilter. DocumentFilter method, funnels into | |
| replace | back to summary |
|---|---|
| pack-priv boolean replace(DefaultFormatter. If the edit described by All of the DocumentFilter methods funnel into here, you should generally only have to override this. | |
| repositionCursor | back to summary |
|---|---|
| pack-priv void repositionCursor(int offset, int direction) Resets the cursor by using getNextCursorPosition. | |
| setAllowsInvalid | back to summary |
|---|---|
| public void setAllowsInvalid(boolean allowsInvalid) Sets whether or not the value being edited is allowed to be invalid
for a length of time (that is,
| |
| setCommitsOnValidEdit | back to summary |
|---|---|
| public void setCommitsOnValidEdit(boolean commit) Sets when edits are published back to the
| |
| setDot | back to summary |
|---|---|
| pack-priv void setDot(NavigationFilter. NavigationFilter method, subclasses that wish finer control should override this. | |
| setOverwriteMode | back to summary |
|---|---|
| public void setOverwriteMode(boolean overwriteMode) Configures the behavior when inserting characters. If
| |
| setValueClass | back to summary |
|---|---|
| public void setValueClass(Class<?> valueClass) 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.
| |
| stringToValue | back to summary |
|---|---|
| public Object stringToValue(String string) throws ParseException Implements abstract javax. Converts the passed in String into an instance of
| |
| updateValue | back to summary |
|---|---|
| pack-priv void updateValue() Pushes the value to the JFormattedTextField if the current value
is valid and invokes | |
| updateValue | back to summary |
|---|---|
| pack-priv void updateValue(Object value) Pushes the | |
| valueToString | back to summary |
|---|---|
| public String valueToString(Object value) throws ParseException Implements abstract javax. Converts the passed in Object into a String by way of the
| |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public void | insertString(DocumentFilter.
Overrides javax. Invoked prior to insertion of text into the specified Document. |
| public void | remove(DocumentFilter.
Overrides javax. Invoked prior to removal of the specified region in the specified Document. |
| public void | replace(DocumentFilter.
Overrides javax. Invoked prior to replacing a region of text in the specified Document. |
| DefaultDocumentFilter | back to summary |
|---|---|
| private DefaultDocumentFilter() | |
| insertString | back to summary |
|---|---|
| public void insertString(DocumentFilter. Overrides javax. Doc from javax. Invoked prior to insertion of text into the specified Document. Subclasses that want to conditionally allow insertion should override this and only call supers implementation as necessary, or call directly into the FilterBypass.
| |
| remove | back to summary |
|---|---|
| public void remove(DocumentFilter. Overrides javax. Doc from javax. Invoked prior to removal of the specified region in the
specified Document. Subclasses that want to conditionally allow
removal should override this and only call supers implementation as
necessary, or call directly into the
| |
| replace | back to summary |
|---|---|
| public void replace(DocumentFilter. Overrides javax. Doc from javax. Invoked prior to replacing a region of text in the specified Document. Subclasses that want to conditionally allow replace should override this and only call supers implementation as necessary, or call directly into the FilterBypass.
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv AttributeSet | attrs
AttributeSet to attach to text, may be null. |
| pack-priv int | cursorPosition
Position the cursor should be adjusted from. |
| pack-priv DocumentFilter. | fb
The FilterBypass that was passed to the DocumentFilter method. |
| pack-priv int | length
Length of text to remove. |
| pack-priv int | offset
Offset where the remove/insert is going to occur. |
| pack-priv String | text
The text to insert, may be null. |
| pack-priv Object | value
The resulting value, this may never be set. |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void |
| attrs | back to summary |
|---|---|
| pack-priv AttributeSet attrs AttributeSet to attach to text, may be null. | |
| cursorPosition | back to summary |
|---|---|
| pack-priv int cursorPosition Position the cursor should be adjusted from. If this is -1 the cursor position will be adjusted based on the direction of the replace (-1: offset, 1: offset + text.length()), otherwise the cursor position is adjusted from this position. | |
| fb | back to summary |
|---|---|
| pack-priv DocumentFilter. The FilterBypass that was passed to the DocumentFilter method. | |
| length | back to summary |
|---|---|
| pack-priv int length Length of text to remove. | |
| offset | back to summary |
|---|---|
| pack-priv int offset Offset where the remove/insert is going to occur. | |
| text | back to summary |
|---|---|
| pack-priv String text The text to insert, may be null. | |
| value | back to summary |
|---|---|
| pack-priv Object value The resulting value, this may never be set. | |
| ReplaceHolder | back to summary |
|---|---|
| pack-priv ReplaceHolder() | |
| reset | back to summary |
|---|---|
| pack-priv void reset(DocumentFilter. | |