primarily by having a
in addition to its content (accessed by the
text property). The user may manipulate the
field’s content, but its
doesn’t (necessarily) change until the user commits
the edit. If the user cancels the edit, the content reverts back to the
most recent valid value.
value may be of any
Object type, but it is displayed and
edited as a
String. The field uses
formatter to translate between
JFormattedTextField works by
AbstractFormatterFactory (defined as a public
abstract inner class). Whenever the field receives focus, it obtains an
AbstractFormatter (another public
abstract inner class) from the factory to oversee editing until it loses
focus. It also queries the factory for a formatter at other times, such
as when it loses focus or when
) is called.
The factory does not generally create new objects (as other
factory classes typically do), but usually just hands out an appropriate
existing formatter instance for the field to use. The factory is used to
permit different formatters to be used for viewing versus editing, not
to support a variety of different types.
JFormattedTextField does support a variety of
types, but its constructor creates a custom factory for the type passed
in. So if you create a
JFormattedTextField(new java.util.Date( )), every formatter it gets from its factory is for dates, ...