javax.swing.text
public class MaskFormatter extends DefaultFormatter
Constructor and Description |
---|
MaskFormatter() |
MaskFormatter(String mask)
Creates a MaskFormatter with the specified mask.
|
Modifier and Type | Method and Description |
---|---|
String |
getInvalidCharacters()
Returns a String containing the characters that are not valid for input
for this MaskFormatter.
|
String |
getMask()
Returns the mask used in this MaskFormatter.
|
String |
getPlaceholder()
Returns the place holder String that is used in place of missing
characters when the value doesn't completely fill in the spaces
in the mask.
|
char |
getPlaceholderCharacter()
Returns the character used in place of missing characters when the
value doesn't completely fill the mask.
|
String |
getValidCharacters()
Returns a String containing the characters that are valid for input
for this MaskFormatter.
|
boolean |
getValueContainsLiteralCharacters()
Returns true if stringToValue should return the literal
characters in the mask.
|
void |
install(JFormattedTextField ftf)
Installs this MaskFormatter on the JFormattedTextField.
|
void |
setInvalidCharacters(String invalidCharacters)
Sets characters that are not valid for input.
|
void |
setMask(String mask)
Sets the mask for this MaskFormatter.
|
void |
setPlaceholder(String placeholder)
Sets the string to use if the value does not completely fill in the mask.
|
void |
setPlaceholderCharacter(char placeholder)
Sets the char to use if the value does not completely fill in the mask.
|
void |
setValidCharacters(String validCharacters)
Sets characters that are valid for input.
|
void |
setValueContainsLiteralCharacters(boolean containsLiteralChars)
Determines whether stringToValue will return literal characters or not.
|
Object |
stringToValue(String value)
Parses the text using the mask, valid characters, and invalid characters
to determine the appropriate Object to return.
|
String |
valueToString(Object value)
Returns a String representation of the Object value based on the mask.
|
clone, getAllowsInvalid, getCommitsOnValidEdit, getDocumentFilter, getOverwriteMode, getValueClass, setAllowsInvalid, setCommitsOnValidEdit, setOverwriteMode, setValueClass
getActions, getFormattedTextField, getNavigationFilter, invalidEdit, setEditValid, uninstall
public MaskFormatter()
public MaskFormatter(String mask) throws ParseException
mask
- ParseException
public String getMask()
public String getInvalidCharacters()
public void setInvalidCharacters(String invalidCharacters)
invalidCharacters
is non-null then no characters contained
in it will be allowed to be input.invalidCharacters
- the String specifying invalid characters.public String getValidCharacters()
public void setValidCharacters(String validCharacters)
validCharacters
is non-null then no characters that are
not contained in it will be allowed to be input.validCharacters
- the String specifying valid characters.public String getPlaceholder()
public void setPlaceholder(String placeholder)
placeholder
- the String to use if the value doesn't completely
fill in the mask.public char getPlaceholderCharacter()
public void setPlaceholderCharacter(char placeholder)
placeholder
- the char to use if the value doesn't completely
fill in the mask.public boolean getValueContainsLiteralCharacters()
public void setValueContainsLiteralCharacters(boolean containsLiteralChars)
containsLiteralChars
- if true, stringToValue will return the
literal characters in the mask, otherwise it will not.public void setMask(String mask) throws ParseException
mask
- the new mask for this MaskFormatterParseException
- if mask
is not valid.public void install(JFormattedTextField ftf)
install
in class DefaultFormatter
ftf
- the JFormattedTextField
in which this formatter
is installedpublic Object stringToValue(String value) throws ParseException
stringToValue
in class DefaultFormatter
value
- the String to parseParseException
- if value doesn't match the mask and valid/invalid
character setspublic String valueToString(Object value) throws ParseException
valueToString
in class DefaultFormatter
value
- the value to convertParseException
- if value is invalid for this mask and valid/invalid
character sets