APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.swing.text

public Class MaskFormatter

extends DefaultFormatter
Class Inheritance
Annotations
@SuppressWarnings:serial
Imports
java.io.IOException, .ObjectInputStream, .Serial, java.text.ParseException, java.util.ArrayList, javax.swing.JFormattedTextField, javax.swing.text.DefaultFormatter

MaskFormatter is used to format and edit strings. The behavior of a MaskFormatter is controlled by way of a String mask that specifies the valid characters that can be contained at a particular location in the Document model. The following characters can be specified:
Valid characters and their descriptions
Character Description
# Any valid number, uses Character.isDigit.
' Escape character, used to escape any of the special formatting characters.
U Any character (Character.isLetter). All lowercase letters are mapped to upper case.
L Any character (Character.isLetter). All upper case letters are mapped to lower case.
A Any character or number (Character.isLetter or Character.isDigit).
? Any character (Character.isLetter).
* Anything.
H Any hex character (0-9, a-f or A-F).

Typically characters correspond to one char, but in certain languages this is not the case. The mask is on a per character basis, and will thus adjust to fit as many chars as are needed.

You can further restrict the characters that can be input by the setInvalidCharacters and setValidCharacters methods. setInvalidCharacters allows you to specify which characters are not legal. setValidCharacters allows you to specify which characters are valid. For example, the following code block is equivalent to a mask of '0xHHH' with no invalid/valid characters:

MaskFormatter formatter = new MaskFormatter("0x***");
formatter.setValidCharacters("0123456789abcdefABCDEF");

When initially formatting a value if the length of the string is less than the length of the mask, two things can happen. Either the placeholder string will be used, or the placeholder character will be used. Precedence is given to the placeholder string. For example:

  MaskFormatter formatter = new MaskFormatter("###-####");
  formatter.setPlaceholderCharacter('_');
  System.out.println(formatter.valueToString("123"));

Would result in the string '123-____'. If setPlaceholder("555-1212") was invoked '123-1212' would result. The placeholder String is only used on the initial format, on subsequent formats only the placeholder character will be used.

If a MaskFormatter is configured to only allow valid characters (setAllowsInvalid(false)) literal characters will be skipped as necessary when editing. Consider a MaskFormatter with the mask "###-####" and current value "555-1212". Using the right arrow key to navigate through the field will result in (| indicates the position of the caret):

  |555-1212
  5|55-1212
  55|5-1212
  555-|1212
  555-1|212
The '-' is a literal (non-editable) character, and is skipped.

Similar behavior will result when editing. Consider inserting the string '123-45' and '12345' into the MaskFormatter in the previous example. Both inserts will result in the same String, '123-45__'. When MaskFormatter is processing the insert at character position 3 (the '-'), two things can happen:

  1. If the inserted character is '-', it is accepted.
  2. If the inserted character matches the mask for the next non-literal character, it is accepted at the new location.
  3. Anything else results in an invalid edit

By default MaskFormatter will not allow invalid edits, you can change this with the setAllowsInvalid method, and will commit edits on valid edits (use the setCommitsOnValidEdit to change this).

By default, MaskFormatter is in overwrite mode. That is as characters are typed a new character is not inserted, rather the character at the current location is replaced with the newly typed character. You can change this behavior by way of the method setOverwriteMode.

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.beans.XMLEncoder.

Since
1.4

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
MaskFormatter.AlphaNumericCharacter

Represents either a character or digit, uses Character.isLetterOrDigit.

private class
MaskFormatter.CharCharacter

Represents a letter, uses Character.isLetter.

private class
MaskFormatter.DigitMaskCharacter

Represents a number, uses Character.isDigit.

private class
MaskFormatter.HexCharacter

Represents a hex character, 0-9a-fA-F. a-f is mapped to A-F

private class
MaskFormatter.LiteralCharacter

Used to represent a fixed character in the mask.

private class
MaskFormatter.LowerCaseCharacter

Represents a character, upper case letters are mapped to lower case using Character.toLowerCase.

private class
private class
MaskFormatter.UpperCaseCharacter

Represents a character, lower case letters are mapped to upper case using Character.toUpperCase.

Field Summary

Modifier and TypeField and Description
private static final char
private static final char
private static final char
private boolean
containsLiteralChars

Indicates if the value contains the literal characters.

private static final char
private static final MaskFormatter.MaskCharacter[]
private static final char
private String
invalidCharacters

List of invalid characters.

private static final char
private static final char
private String
mask

The user specified mask.

private transient MaskFormatter.MaskCharacter[]
private char
placeholder

String used to represent characters not present.

private String
placeholderString

String used for the passed in value if it does not completely fill the mask.

private static final char
private String
validCharacters

List of valid characters.

Inherited from javax.swing.text.DefaultFormatter:
replaceHolder

Constructor Summary

AccessConstructor and Description
public
MaskFormatter()

Creates a MaskFormatter with no mask.

public
MaskFormatter(String
the mask
mask
)

Creates a MaskFormatter with the specified mask.

Method Summary

Modifier and TypeMethod and Description
private void
append(StringBuilder result, String value, int[] index, String placeholder, MaskFormatter.MaskCharacter[] mask)

Invokes append on the mask characters in mask.

pack-priv boolean
canReplace(DefaultFormatter.ReplaceHolder rh)

Overrides javax.swing.text.DefaultFormatter.canReplace.

This method does the following (assuming !getAllowsInvalid()): iterate over the max of the deleted region or the text length, for each character:

  1. If it is valid (matches the mask at the particular position, or matches the literal character at the position), allow it
  2. Else if the position identifies a literal character, add it. This allows for the user to paste in text that may/may not contain the literals. For example, in passing in 5551212 into ###-#### when the 1 is evaluated it is illegal (by the first test), but there is a literal at this position (-), so it is used. NOTE: This has a problem that you can't tell (without looking ahead) if you should eat literals in the text. For example, if you paste '555' into #5##, should it result in '5555' or '555 '? The current code will result in the latter, which feels a little better as selecting text than pasting will always result in the same thing.
  3. Else if at the end of the inserted text, the replace the item with the placeholder
  4. Otherwise the insert is bogus and false is returned.
private char
getCharacter(int index, char aChar)

Returns the character to insert at the specified location based on the passed in character.

public String

Returns:

illegal characters.
getInvalidCharacters
()

Returns the characters that are not valid for input.

private int
getInvalidOffset(String string, boolean completeMatch)

Returns -1 if the passed in string is valid, otherwise the index of the first bogus character is returned.

private char
getLiteral(int index)

Returns the literal character at the specified location.

public String

Returns:

Mask dictating legal character values.
getMask
()

Returns the formatting mask.

private MaskFormatter.MaskCharacter
getMaskCharacter(int index)

Returns the MaskCharacter at the specified location.

private int
getMaxLength()

Returns the maximum length the text can be.

public String

Returns:

String used when formatting if the value does not completely fill the mask
getPlaceholder
()

Returns the String to use if the value does not completely fill in the mask.

public char

Returns:

Character used when formatting if the value does not completely fill the mask
getPlaceholderCharacter
()

Returns the character to use in place of characters that are not present in the value, ie the user must fill them in.

public String

Returns:

Legal characters
getValidCharacters
()

Returns the valid characters that can be input.

public boolean

Returns:

True if literal characters in mask should be returned in stringToValue
getValueContainsLiteralCharacters
()

Returns true if stringToValue should return literal characters in the mask.

public void
install(JFormattedTextField
JFormattedTextField to format for, may be null indicating uninstall from current JFormattedTextField.
ftf
)

Overrides javax.swing.text.DefaultFormatter.install.

Installs the DefaultFormatter onto a particular JFormattedTextField.

private boolean
isLiteral(int index)

Returns true if the character at the specified location is a literal, that is it can not be edited.

pack-priv boolean
isNavigatable(int offset)

Overrides javax.swing.text.DefaultFormatter.isNavigatable.

Returns true if the MaskFormatter allows invalid, or the offset is less than the max length and the character at offset is a literal.

private boolean
isPlaceholder(int index, char aChar)

Returns true if the placeholder character matches aChar.

private boolean
isValidCharacter(int index, char aChar)

Returns true if the passed in character matches the mask at the specified location.

pack-priv boolean
private void
readObject(ObjectInputStream s)

Subclassed to update the internal representation of the mask after the default read operation has completed.

public void
setInvalidCharacters(String
If non-null, specifies illegal characters.
invalidCharacters
)

Allows for further restricting of the characters that can be input.

public void
setMask(String
the mask
mask
)

Sets the mask dictating the legal characters.

public void
setPlaceholder(String
String used when formatting if the value does not completely fill the mask
placeholder
)

Sets the string to use if the value does not completely fill in the mask.

public void
setPlaceholderCharacter(char
Character used when formatting if the value does not completely fill the mask
placeholder
)

Sets the character to use in place of characters that are not present in the value, ie the user must fill them in. The default value is a space.

public void
setValidCharacters(String
If non-null, specifies legal characters.
validCharacters
)

Allows for further restricting of the characters that can be input.

public void
setValueContainsLiteralCharacters(boolean
Used to indicate if literal characters in mask should be returned in stringToValue
containsLiteralChars
)

If true, the returned value and set value will also contain the literal characters in mask.

public Object

Returns:

Object representation of text
stringToValue
(String
String to convert
value
)

Overrides javax.swing.text.DefaultFormatter.stringToValue.

Parses the text, returning the appropriate Object representation of the String value.

private Object
stringToValue(String value, boolean completeMatch)

Actual stringToValue implementation.

private String
stripLiteralChars(String string)

Removes the literal characters from the passed in string.

private void
updateInternalMask()

Updates the internal representation of the mask.

public String

Returns:

String representation of value
valueToString
(Object
Value to convert
value
)

Overrides javax.swing.text.DefaultFormatter.valueToString.

Returns a String representation of the Object value based on the mask.

Inherited from javax.swing.text.DefaultFormatter:
clonecommitEditgetAllowsInvalidgetCommitsOnValidEditgetDocumentFiltergetInitialVisualPositiongetNavigationFiltergetNextCursorPositiongetNextVisualPositionFromgetOverwriteModegetReplaceHoldergetReplaceStringgetValueClassisLegalInsertTextmoveDotpositionCursorAtInitialLocationreplacereplacerepositionCursorsetAllowsInvalidsetCommitsOnValidEditsetDotsetOverwriteModesetValueClassupdateValueupdateValue

Field Detail

ALPHA_NUMERIC_KEYback to summary
private static final char ALPHA_NUMERIC_KEY
ANYTHING_KEYback to summary
private static final char ANYTHING_KEY
CHARACTER_KEYback to summary
private static final char CHARACTER_KEY
containsLiteralCharsback to summary
private boolean containsLiteralChars

Indicates if the value contains the literal characters.

DIGIT_KEYback to summary
private static final char DIGIT_KEY
EmptyMaskCharsback to summary
private static final MaskFormatter.MaskCharacter[] EmptyMaskChars
HEX_KEYback to summary
private static final char HEX_KEY
invalidCharactersback to summary
private String invalidCharacters

List of invalid characters.

LITERAL_KEYback to summary
private static final char LITERAL_KEY
LOWERCASE_KEYback to summary
private static final char LOWERCASE_KEY
maskback to summary
private String mask

The user specified mask.

maskCharsback to summary
private transient MaskFormatter.MaskCharacter[] maskChars
placeholderback to summary
private char placeholder

String used to represent characters not present.

placeholderStringback to summary
private String placeholderString

String used for the passed in value if it does not completely fill the mask.

UPPERCASE_KEYback to summary
private static final char UPPERCASE_KEY
validCharactersback to summary
private String validCharacters

List of valid characters.

Constructor Detail

MaskFormatterback to summary
public MaskFormatter()

Creates a MaskFormatter with no mask.

MaskFormatterback to summary
public MaskFormatter(String mask) throws ParseException

Creates a MaskFormatter with the specified mask. A ParseException will be thrown if mask is an invalid mask.

Parameters
mask:String

the mask

Exceptions
ParseException:
if mask does not contain valid mask characters

Method Detail

appendback to summary
private void append(StringBuilder result, String value, int[] index, String placeholder, MaskFormatter.MaskCharacter[] mask) throws ParseException

Invokes append on the mask characters in mask.

canReplaceback to summary
pack-priv boolean canReplace(DefaultFormatter.ReplaceHolder rh)

Overrides javax.swing.text.DefaultFormatter.canReplace.

This method does the following (assuming !getAllowsInvalid()): iterate over the max of the deleted region or the text length, for each character:

  1. If it is valid (matches the mask at the particular position, or matches the literal character at the position), allow it
  2. Else if the position identifies a literal character, add it. This allows for the user to paste in text that may/may not contain the literals. For example, in passing in 5551212 into ###-#### when the 1 is evaluated it is illegal (by the first test), but there is a literal at this position (-), so it is used. NOTE: This has a problem that you can't tell (without looking ahead) if you should eat literals in the text. For example, if you paste '555' into #5##, should it result in '5555' or '555 '? The current code will result in the latter, which feels a little better as selecting text than pasting will always result in the same thing.
  3. Else if at the end of the inserted text, the replace the item with the placeholder
  4. Otherwise the insert is bogus and false is returned.
getCharacterback to summary
private char getCharacter(int index, char aChar)

Returns the character to insert at the specified location based on the passed in character. This provides a way to map certain sets of characters to alternative values (lowercase to uppercase...).

getInvalidCharactersback to summary
public String getInvalidCharacters()

Returns the characters that are not valid for input.

Returns:String

illegal characters.

getInvalidOffsetback to summary
private int getInvalidOffset(String string, boolean completeMatch)

Returns -1 if the passed in string is valid, otherwise the index of the first bogus character is returned.

getLiteralback to summary
private char getLiteral(int index)

Returns the literal character at the specified location.

getMaskback to summary
public String getMask()

Returns the formatting mask.

Returns:String

Mask dictating legal character values.

getMaskCharacterback to summary
private MaskFormatter.MaskCharacter getMaskCharacter(int index)

Returns the MaskCharacter at the specified location.

getMaxLengthback to summary
private int getMaxLength()

Returns the maximum length the text can be.

getPlaceholderback to summary
public String getPlaceholder()

Returns the String to use if the value does not completely fill in the mask.

Returns:String

String used when formatting if the value does not completely fill the mask

getPlaceholderCharacterback to summary
public char getPlaceholderCharacter()

Returns the character to use in place of characters that are not present in the value, ie the user must fill them in.

Returns:char

Character used when formatting if the value does not completely fill the mask

getValidCharactersback to summary
public String getValidCharacters()

Returns the valid characters that can be input.

Returns:String

Legal characters

getValueContainsLiteralCharactersback to summary
public boolean getValueContainsLiteralCharacters()

Returns true if stringToValue should return literal characters in the mask.

Returns:boolean

True if literal characters in mask should be returned in stringToValue

installback to summary
public void install(JFormattedTextField ftf)

Overrides javax.swing.text.DefaultFormatter.install.

Installs the 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 Actions 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.

Parameters
ftf:JFormattedTextField

JFormattedTextField to format for, may be null indicating uninstall from current JFormattedTextField.

isLiteralback to summary
private boolean isLiteral(int index)

Returns true if the character at the specified location is a literal, that is it can not be edited.

isNavigatableback to summary
pack-priv boolean isNavigatable(int offset)

Overrides javax.swing.text.DefaultFormatter.isNavigatable.

Returns true if the MaskFormatter allows invalid, or the offset is less than the max length and the character at offset is a literal.

isPlaceholderback to summary
private boolean isPlaceholder(int index, char aChar)

Returns true if the placeholder character matches aChar.

isValidCharacterback to summary
private boolean isValidCharacter(int index, char aChar)

Returns true if the passed in character matches the mask at the specified location.

isValidEditback to summary
pack-priv boolean isValidEdit(DefaultFormatter.ReplaceHolder rh)

Overrides javax.swing.text.DefaultFormatter.isValidEdit.

readObjectback to summary
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException

Subclassed to update the internal representation of the mask after the default read operation has completed.

Annotations
@Serial
setInvalidCharactersback to summary
public void setInvalidCharacters(String invalidCharacters)

Allows for further restricting of the characters that can be input. Only characters specified in the mask, not in the invalidCharacters, and in validCharacters will be allowed to be input. Passing in null (the default) implies the valid characters are only bound by the mask and the valid characters.

Parameters
invalidCharacters:String

If non-null, specifies illegal characters.

setMaskback to summary
public void setMask(String mask) throws ParseException

Sets the mask dictating the legal characters. This will throw a ParseException if mask is not valid.

Parameters
mask:String

the mask

Exceptions
ParseException:
if mask does not contain valid mask characters
setPlaceholderback to summary
public void setPlaceholder(String placeholder)

Sets the string to use if the value does not completely fill in the mask. A null value implies the placeholder char should be used.

Parameters
placeholder:String

String used when formatting if the value does not completely fill the mask

setPlaceholderCharacterback to summary
public void setPlaceholderCharacter(char placeholder)

Sets the character to use in place of characters that are not present in the value, ie the user must fill them in. The default value is a space.

This is only applicable if the placeholder string has not been specified, or does not completely fill in the mask.

Parameters
placeholder:char

Character used when formatting if the value does not completely fill the mask

setValidCharactersback to summary
public void setValidCharacters(String validCharacters)

Allows for further restricting of the characters that can be input. Only characters specified in the mask, not in the invalidCharacters, and in validCharacters will be allowed to be input. Passing in null (the default) implies the valid characters are only bound by the mask and the invalid characters.

Parameters
validCharacters:String

If non-null, specifies legal characters.

setValueContainsLiteralCharactersback to summary
public void setValueContainsLiteralCharacters(boolean containsLiteralChars)

If true, the returned value and set value will also contain the literal characters in mask.

For example, if the mask is '(###) ###-####', the current value is '(415) 555-1212', and valueContainsLiteralCharacters is true stringToValue will return '(415) 555-1212'. On the other hand, if valueContainsLiteralCharacters is false, stringToValue will return '4155551212'.

Parameters
containsLiteralChars:boolean

Used to indicate if literal characters in mask should be returned in stringToValue

stringToValueback to summary
public Object stringToValue(String value) throws ParseException

Overrides javax.swing.text.DefaultFormatter.stringToValue.

Parses the text, returning the appropriate Object representation of the String value. This strips the literal characters as necessary and invokes supers stringToValue, so that if you have specified a value class (setValueClass) an instance of it will be created. This will throw a ParseException if the value does not match the current mask. Refer to setValueContainsLiteralCharacters for details on how literals are treated.

Parameters
value:String

String to convert

Returns:Object

Object representation of text

Exceptions
ParseException:
if there is an error in the conversion
See Also
setValueContainsLiteralCharacters
stringToValueback to summary
private Object stringToValue(String value, boolean completeMatch) throws ParseException

Actual stringToValue implementation. If completeMatch is true, the value must exactly match the mask, on the other hand if completeMatch is false the string must match the mask or the placeholder string.

stripLiteralCharsback to summary
private String stripLiteralChars(String string)

Removes the literal characters from the passed in string.

updateInternalMaskback to summary
private void updateInternalMask() throws ParseException

Updates the internal representation of the mask.

valueToStringback to summary
public String valueToString(Object value) throws ParseException

Overrides javax.swing.text.DefaultFormatter.valueToString.

Returns a String representation of the Object value based on the mask. Refer to setValueContainsLiteralCharacters for details on how literals are treated.

Parameters
value:Object

Value to convert

Returns:String

String representation of value

Exceptions
ParseException:
if there is an error in the conversion
See Also
setValueContainsLiteralCharacters
javax.swing.text back to summary

private Class MaskFormatter.AlphaNumericCharacter

extends MaskCharacter
Class Inheritance

Represents either a character or digit, uses Character.isLetterOrDigit.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
isValidCharacter(char aChar)

Overrides javax.swing.text.MaskFormatter.MaskCharacter.isValidCharacter.

Returns true if aChar is a valid representation of the receiver.

Inherited from javax.swing.text.MaskFormatter.MaskCharacter:
appendgetCharisLiteral

Constructor Detail

AlphaNumericCharacterback to summary
private AlphaNumericCharacter()

Method Detail

isValidCharacterback to summary
public boolean isValidCharacter(char aChar)

Overrides javax.swing.text.MaskFormatter.MaskCharacter.isValidCharacter.

Doc from javax.swing.text.MaskFormatter.MaskCharacter.isValidCharacter.

Returns true if aChar is a valid representation of the receiver. The default implementation returns true if the receiver represents a literal character and getChar == aChar. Otherwise, this will return true is aChar is contained in the valid characters and not contained in the invalid characters.

javax.swing.text back to summary

private Class MaskFormatter.CharCharacter

extends MaskCharacter
Class Inheritance

Represents a letter, uses Character.isLetter.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
isValidCharacter(char aChar)

Overrides javax.swing.text.MaskFormatter.MaskCharacter.isValidCharacter.

Returns true if aChar is a valid representation of the receiver.

Inherited from javax.swing.text.MaskFormatter.MaskCharacter:
appendgetCharisLiteral

Constructor Detail

CharCharacterback to summary
private CharCharacter()

Method Detail

isValidCharacterback to summary
public boolean isValidCharacter(char aChar)

Overrides javax.swing.text.MaskFormatter.MaskCharacter.isValidCharacter.

Doc from javax.swing.text.MaskFormatter.MaskCharacter.isValidCharacter.

Returns true if aChar is a valid representation of the receiver. The default implementation returns true if the receiver represents a literal character and getChar == aChar. Otherwise, this will return true is aChar is contained in the valid characters and not contained in the invalid characters.

javax.swing.text back to summary

private Class MaskFormatter.DigitMaskCharacter

extends MaskCharacter
Class Inheritance

Represents a number, uses Character.isDigit.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
isValidCharacter(char aChar)

Overrides javax.swing.text.MaskFormatter.MaskCharacter.isValidCharacter.

Returns true if aChar is a valid representation of the receiver.

Inherited from javax.swing.text.MaskFormatter.MaskCharacter:
appendgetCharisLiteral

Constructor Detail

DigitMaskCharacterback to summary
private DigitMaskCharacter()

Method Detail

isValidCharacterback to summary
public boolean isValidCharacter(char aChar)

Overrides javax.swing.text.MaskFormatter.MaskCharacter.isValidCharacter.

Doc from javax.swing.text.MaskFormatter.MaskCharacter.isValidCharacter.

Returns true if aChar is a valid representation of the receiver. The default implementation returns true if the receiver represents a literal character and getChar == aChar. Otherwise, this will return true is aChar is contained in the valid characters and not contained in the invalid characters.

javax.swing.text back to summary

private Class MaskFormatter.HexCharacter

extends MaskCharacter
Class Inheritance

Represents a hex character, 0-9a-fA-F. a-f is mapped to A-F

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public char
getChar(char aChar)

Overrides javax.swing.text.MaskFormatter.MaskCharacter.getChar.

Returns the character to insert for aChar.

public boolean
isValidCharacter(char aChar)

Overrides javax.swing.text.MaskFormatter.MaskCharacter.isValidCharacter.

Returns true if aChar is a valid representation of the receiver.

Inherited from javax.swing.text.MaskFormatter.MaskCharacter:
appendisLiteral

Constructor Detail

HexCharacterback to summary
private HexCharacter()

Method Detail

getCharback to summary
public char getChar(char aChar)

Overrides javax.swing.text.MaskFormatter.MaskCharacter.getChar.

Doc from javax.swing.text.MaskFormatter.MaskCharacter.getChar.

Returns the character to insert for aChar. The default implementation returns aChar. Subclasses that wish to do some sort of mapping, perhaps lower case to upper case should override this and do the necessary mapping.

isValidCharacterback to summary
public boolean isValidCharacter(char aChar)

Overrides javax.swing.text.MaskFormatter.MaskCharacter.isValidCharacter.

Doc from javax.swing.text.MaskFormatter.MaskCharacter.isValidCharacter.

Returns true if aChar is a valid representation of the receiver. The default implementation returns true if the receiver represents a literal character and getChar == aChar. Otherwise, this will return true is aChar is contained in the valid characters and not contained in the invalid characters.

javax.swing.text back to summary

private Class MaskFormatter.LiteralCharacter

extends MaskCharacter
Class Inheritance

Used to represent a fixed character in the mask.

Field Summary

Modifier and TypeField and Description
private char

Constructor Summary

AccessConstructor and Description
public
LiteralCharacter(char fixedChar)

Method Summary

Modifier and TypeMethod and Description
public char
getChar(char aChar)

Overrides javax.swing.text.MaskFormatter.MaskCharacter.getChar.

Returns the character to insert for aChar.

public boolean
isLiteral()

Overrides javax.swing.text.MaskFormatter.MaskCharacter.isLiteral.

Subclasses should override this returning true if the instance represents a literal character.

Inherited from javax.swing.text.MaskFormatter.MaskCharacter:
appendisValidCharacter

Field Detail

fixedCharback to summary
private char fixedChar

Constructor Detail

LiteralCharacterback to summary
public LiteralCharacter(char fixedChar)

Method Detail

getCharback to summary
public char getChar(char aChar)

Overrides javax.swing.text.MaskFormatter.MaskCharacter.getChar.

Doc from javax.swing.text.MaskFormatter.MaskCharacter.getChar.

Returns the character to insert for aChar. The default implementation returns aChar. Subclasses that wish to do some sort of mapping, perhaps lower case to upper case should override this and do the necessary mapping.

isLiteralback to summary
public boolean isLiteral()

Overrides javax.swing.text.MaskFormatter.MaskCharacter.isLiteral.

Doc from javax.swing.text.MaskFormatter.MaskCharacter.isLiteral.

Subclasses should override this returning true if the instance represents a literal character. The default implementation returns false.

javax.swing.text back to summary

private Class MaskFormatter.LowerCaseCharacter

extends MaskCharacter
Class Inheritance

Represents a character, upper case letters are mapped to lower case using Character.toLowerCase.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public char
getChar(char aChar)

Overrides javax.swing.text.MaskFormatter.MaskCharacter.getChar.

Returns the character to insert for aChar.

public boolean
isValidCharacter(char aChar)

Overrides javax.swing.text.MaskFormatter.MaskCharacter.isValidCharacter.

Returns true if aChar is a valid representation of the receiver.

Inherited from javax.swing.text.MaskFormatter.MaskCharacter:
appendisLiteral

Constructor Detail

LowerCaseCharacterback to summary
private LowerCaseCharacter()

Method Detail

getCharback to summary
public char getChar(char aChar)

Overrides javax.swing.text.MaskFormatter.MaskCharacter.getChar.

Doc from javax.swing.text.MaskFormatter.MaskCharacter.getChar.

Returns the character to insert for aChar. The default implementation returns aChar. Subclasses that wish to do some sort of mapping, perhaps lower case to upper case should override this and do the necessary mapping.

isValidCharacterback to summary
public boolean isValidCharacter(char aChar)

Overrides javax.swing.text.MaskFormatter.MaskCharacter.isValidCharacter.

Doc from javax.swing.text.MaskFormatter.MaskCharacter.isValidCharacter.

Returns true if aChar is a valid representation of the receiver. The default implementation returns true if the receiver represents a literal character and getChar == aChar. Otherwise, this will return true is aChar is contained in the valid characters and not contained in the invalid characters.

javax.swing.text back to summary

private Class MaskFormatter.MaskCharacter

extends Object
Class Inheritance
Known Direct Subclasses
javax.swing.text.MaskFormatter.LiteralCharacter, javax.swing.text.MaskFormatter.DigitMaskCharacter, javax.swing.text.MaskFormatter.UpperCaseCharacter, javax.swing.text.MaskFormatter.LowerCaseCharacter, javax.swing.text.MaskFormatter.AlphaNumericCharacter, javax.swing.text.MaskFormatter.CharCharacter, javax.swing.text.MaskFormatter.HexCharacter

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
append(StringBuilder buff, String formatting, int[] index, String placeholder)

Appends the necessary character in formatting at index to buff.

public char
getChar(char aChar)

Returns the character to insert for aChar.

public boolean
isLiteral()

Subclasses should override this returning true if the instance represents a literal character.

public boolean
isValidCharacter(char aChar)

Returns true if aChar is a valid representation of the receiver.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

MaskCharacterback to summary
private MaskCharacter()

Method Detail

appendback to summary
public void append(StringBuilder buff, String formatting, int[] index, String placeholder) throws ParseException

Appends the necessary character in formatting at index to buff.

getCharback to summary
public char getChar(char aChar)

Returns the character to insert for aChar. The default implementation returns aChar. Subclasses that wish to do some sort of mapping, perhaps lower case to upper case should override this and do the necessary mapping.

isLiteralback to summary
public boolean isLiteral()

Subclasses should override this returning true if the instance represents a literal character. The default implementation returns false.

isValidCharacterback to summary
public boolean isValidCharacter(char aChar)

Returns true if aChar is a valid representation of the receiver. The default implementation returns true if the receiver represents a literal character and getChar == aChar. Otherwise, this will return true is aChar is contained in the valid characters and not contained in the invalid characters.

javax.swing.text back to summary

private Class MaskFormatter.UpperCaseCharacter

extends MaskCharacter
Class Inheritance

Represents a character, lower case letters are mapped to upper case using Character.toUpperCase.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public char
getChar(char aChar)

Overrides javax.swing.text.MaskFormatter.MaskCharacter.getChar.

Returns the character to insert for aChar.

public boolean
isValidCharacter(char aChar)

Overrides javax.swing.text.MaskFormatter.MaskCharacter.isValidCharacter.

Returns true if aChar is a valid representation of the receiver.

Inherited from javax.swing.text.MaskFormatter.MaskCharacter:
appendisLiteral

Constructor Detail

UpperCaseCharacterback to summary
private UpperCaseCharacter()

Method Detail

getCharback to summary
public char getChar(char aChar)

Overrides javax.swing.text.MaskFormatter.MaskCharacter.getChar.

Doc from javax.swing.text.MaskFormatter.MaskCharacter.getChar.

Returns the character to insert for aChar. The default implementation returns aChar. Subclasses that wish to do some sort of mapping, perhaps lower case to upper case should override this and do the necessary mapping.

isValidCharacterback to summary
public boolean isValidCharacter(char aChar)

Overrides javax.swing.text.MaskFormatter.MaskCharacter.isValidCharacter.

Doc from javax.swing.text.MaskFormatter.MaskCharacter.isValidCharacter.

Returns true if aChar is a valid representation of the receiver. The default implementation returns true if the receiver represents a literal character and getChar == aChar. Otherwise, this will return true is aChar is contained in the valid characters and not contained in the invalid characters.