Document is the M
part of the MVC (Model-View-Controller) architecture for all of
Swing’s text components. It is responsible for the text content of the
component as well as relevant style information for text components that
support styled text. The
model must be simple enough to be used by
JTextField, but powerful and flexible enough
to be used by
JEditorPane. Swing accomplishes this by
providing the classes and interfaces shown in Figure 22-7.
Figure 22-7. High-level Document class diagram
partitions its content into small pieces called
Element is small enough that its style
information can be represented by a single
Elements are organized into a tree
structure with a single root.
Swing provides the
interface, which doesn’t support styled text, and the
StyledDocument interface, which does. But note
that there is no
interface. Swing provides a single
Element interface that does support style. The
simpler document types (such as
JTextArea use by default) use
Elements but don’t assign any style
information to them.
is used to describe a portion of a document. But note that an
Element does not actually
contain a portion of the document; it just defines a way of structuring a portion. ...