JFormattedTextField is an editable text field that allows you
to define a field model, which can then specify a formatter, a validator,
a keystroke verifier, and data attributes.
By default, JFormattedTextField
uses an AS400FieldModel, which uses an EditcodeEditwordFormatter, ComparisonRangeValidator,
and NumericCharacterDocument. The default data type is character, data length
is 10, and number of decimal places is 0.
JFormattedTextField has all
the behaviors of a Swing JTextField, but with the following extra features:
- You can restrict the data to numeric or character. If the field is set
to numeric, you can enter only numerals, decimal point, and plus and minus
signs. If the field is a character field, there are no restrictions on the
input.
- You can restrict the data to a particular character set, such as alphanumeric
or uppercase only.
- You can limit the data length to a maximum that you specify. If it is
a numeric field, you can specify the number of significant digits and decimal
places.
- You can specify a currency symbol, decimal point, and thousand separator.
The default values for decimal point and thousand separator are the locale
values.
- You can automatically format the field. If the autoAdvance flag has been
set to true, when you type the same number of characters as the data length,
the bean formats the field, performs the appropriate validation, and passes
control to the next component without requiring the Tab key.
- You can perform a comparison validity check. The comparison types are
Equals, Not equals, Less than, Greater than, Not less than, Not Greater than,
Less than and equals, Greater than and equals. For example, if Equals is specified
with comparison value of ABC, then the field accepts only the data ABC.
- You can perform a range validity check. For example, if the minimum range
property is set to 100 and the maximum range property is set to 500, then
only the values that fall within this range are accepted.
For additional information about Swing architecture, see the following
Web site:
http://java.sun.com/products/jfc/tsc/articles/architecture/index.html