Java Reference
In-Depth Information
Summary
In this chapter, you began to explore the details of the Swing text components. You initially
looked at the root text component,
JTextComponent
, and the many operations it defines for
all other text components. You then explored the specific text components of
JTextField
,
JPasswordField
,
JFormattedTextField
,
JTextArea
,
JEditorPane
, and
JTextPane
.
You also explored the various pieces that make up the different components. You delved
into the data model for the text components, based on the
Document
interface, for the
AbstractDocument
and
PlainDocument
classes. You also looked at creating a custom document
filter via
DocumentFilter
for restricting input to a text component. In addition, you explored the
Caret
and
Highlighter
interfaces for displaying the cursor and highlighted text, the
NavigationFilter
for limiting movement within the text component, as well as the
Keymap
to
make the text component act as the controller. As the controller, the
Keymap
converts a user's
keystrokes into specific actions that affect the model for the text component.
You also looked at how events are handled within the Swing text components. In addition
to the basic AWT event handling classes, Swing adds some new ones designed for listening
for cursor movement with the
CaretListener
and document content changes with the
DocumentListener
. The
JEditorPane
also provides another event handler with the
HyperlinkListener
. And there is the general Swing support for input verification through
InputVerifier
.
In Chapter 16, you'll further explore the Swing text components. This chapter touched on
the basic features of all the components, while the next chapter goes into all the gory details of
working with the
TextAction
, formatting input for a
JFormattedTextField
, and configuring
Style
objects to work with a
StyledDocument
. You'll also look into shuffling through the tags
of your
HTMLDocument
.