In the previous chapter, we introduced the Swing text components, ignoring many of the details in order to simplify the introduction. In this chapter, we’ll give a detailed explanation of the many classes and interfaces that make up the basic text model. Additionally, we’ll look at the classes and interfaces involved in delivering events to provide notification of document model changes.
Before getting into the details of the classes and interfaces that make up the Swing text model, we’ll give a brief overview of the top-level interfaces that serve as the model’s key abstractions. These interfaces, and the relationships between them, are shown in Figure 20.1.
Figure 20-1. High-level Document class diagram
The first—and arguably most important—interface to look
at is called
Document. The model representation of
any text component (even a simple text field) in Swing is defined by
this interface. A
Document is little more than an
arbitrary collection of text (though Swing’s implementations of
the interface provide much more).
Document objects are partitioned by
s that describe the structural
pieces of a
Document, such as paragraphs or
sections of specially formatted text (e.g.,
Elements are made
up of child
Elements, forming a tree with a
Element as the base and
arbitrary levels of child
Elements below ...