O'Reilly logo

Java Swing, 2nd Edition by Brian Cole, James Elliott, Marc Loy, Robert Eckstein, Dave Wood

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The DefaultFormatterFactory Class

DefaultFormatterFactory is Swing’s only concrete implementation of AbstractFormatterFactory. It holds one or more formatters and decides which one to give to the field depending on whether the field has focus and whether the field’s value is null.

Properties

Table 20-7 shows the formatter properties defined by DefaultFormatterFactory.

Table 20-7. DefaultFormatterFactory properties

Property

Data type

get

is

set

Default value

defaultFormatter

JFormattedTextField.AbstractFormatter

·

 

·

null

displayFormatter

JFormattedTextField.AbstractFormatter

·

 

·

null

editFormatter

JFormattedTextField.AbstractFormatter

·

 

·

null

nullFormatter

JFormattedTextField.AbstractFormatter

·

 

·

null

defaultFormatter is used if one of the other formatter properties is null. It is common for defaultFormatter to be the only non-null formatter property, in which case the field uses the defaultFormatter exclusively.

displayFormatter is intended for use when the field does not have focus. It may be null, in which case defaultFormatter is used instead.

editFormatter is intended for use when the field has focus. It may be null, in which case defaultFormatter is used instead.

nullFormatter is intended for use when the field’s content is null. It may be null, in which case displayFormatter or editFormatter (depending on whether the field has focus) is used instead. (If displayFormatter/editFormatter is also null, defaultFormatter is used.)

Constructors

public DefaultFormatterFactory( )

Create a new DefaultFormatterFactory ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required