|
|||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||
java.lang.Object
|
+--javax.swing.JFormattedTextField.AbstractFormatter
|
+--javax.swing.text.DefaultFormatter
|
+--javax.swing.text.InternationalFormatter
InternationalFormatter extends DefaultFormatter,
using an instance of java.text.Format to handle the
conversion to a String, and the conversion from a String.
If getAllowsInvalid() is false, this will ask the
Format to format the current text on every edit.
You can specify a minimum and maximum value by way of the
setMinimum and setMaximum methods. In order
for this to work the values returned from stringToValue must be
comparable to the min/max values by way of the Comparable
interface.
Be careful how you configure the Format and the
InternationalFormatter, as it is possible to create a
situation where certain values can not be input. Consider the date
format 'M/d/yy', an InternationalFormatter that is always
valid (setAllowsInvalid(false)), is in overwrite mode
(setOverwriteMode(true)) and the date 7/1/99. In this
case the user will not be able to enter a two digit month or day of
month. To avoid this, the format should be 'MM/dd/yy'.
If InternationalFormatter is configured to only allow valid
values (setAllowsInvalid(false)), every valid edit will result
in the text of the JFormattedTextField being completely reset
from the Format.
The cursor position will also be adjusted as literal characters are
added/removed from the resulting String.
InternationalFormatter's behavior of
stringToValue is slightly different than that of
DefaultTextFormatter, it does the following:
parseObject is invoked on the Format
specified by setFormat
setValueClass),
supers implementation is invoked to convert the value returned
from parseObject to the appropriate class.
ParseException has not been thrown, and the value
is outside the min/max a ParseException is thrown.
InternationalFormatter implements stringToValue
in this manner so that you can specify an alternate Class than
Format may return.
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. A future release of Swing will provide support for long term persistence.
Format,
Comparable| Constructor Summary | |
InternationalFormatter()
Creates an InternationalFormatter with no Format specified. |
|
InternationalFormatter(java.text.Format format)
Creates an InternationalFormatter with the specified Format instance. |
|
| Method Summary | |
java.text.Format.Field[] |
getFields(int offset)
Returns the Format.Field constants associated with
the text at offset. |
java.text.Format |
getFormat()
Returns the format that dictates the legal values that can be edited and displayed. |
java.lang.Comparable |
getMaximum()
Returns the maximum permissible value. |
java.lang.Comparable |
getMinimum()
Returns the mimum permissible value. |
void |
setFormat(java.text.Format format)
Sets the format that dictates the legal values that can be edited and displayed. |
void |
setMaximum(java.lang.Comparable max)
Sets the maximum permissible value. |
void |
setMinimum(java.lang.Comparable minimum)
Sets the mimum permissible value. |
java.lang.Object |
stringToValue(java.lang.String text)
Returns the Object representation of the String text. |
java.lang.String |
valueToString(java.lang.Object value)
Returns a String representation of the Object value. |
| Methods inherited from class javax.swing.text.DefaultFormatter |
clone, getActions, getAllowsInvalid, getCommitsOnValidEdit, getDocumentFilter, getNavigationFilter, getOverwriteMode, getValueClass, install, setAllowsInvalid, setCommitsOnValidEdit, setOverwriteMode, setValueClass |
| Methods inherited from class javax.swing.JFormattedTextField.AbstractFormatter |
getFormattedTextField, invalidEdit, setEditValid, uninstall |
| Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public InternationalFormatter()
public InternationalFormatter(java.text.Format format)
Format - instance used for converting from/to Strings| Method Detail |
public void setFormat(java.text.Format format)
format - Format instance used for converting from/to Stringspublic java.text.Format getFormat()
public void setMinimum(java.lang.Comparable minimum)
valueClass has
not been specified, and minimum is non null, the
valueClass will be set to that of the class of
minimum.minimum - Minimum legal value that can be inputDefaultFormatter.setValueClass(java.lang.Class)public java.lang.Comparable getMinimum()
public void setMaximum(java.lang.Comparable max)
valueClass has
not been specified, and max is non null, the
valueClass will be set to that of the class of
max.maximum - Maximum legal value that can be inputDefaultFormatter.setValueClass(java.lang.Class)public java.lang.Comparable getMaximum()
public java.lang.String valueToString(java.lang.Object value)
throws java.text.ParseException
value.
This invokes format on the current Format.valueToString in class DefaultFormattervalue - Value to convertjava.text.ParseException - if there is an error in the conversion
public java.lang.Object stringToValue(java.lang.String text)
throws java.text.ParseException
text.stringToValue in class DefaultFormattertf - JTextComponent containing texttext - String to convertjava.text.ParseException - if there is an error in the conversionpublic java.text.Format.Field[] getFields(int offset)
Format.Field constants associated with
the text at offset. If offset is not
a valid location into the current text, this will return an
empty array.
|
|||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||