O'Reilly logo

Java Swing by Dave Wood, Marc Loy, Robert Eckstein

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

Chapter 20. Document Model and Events

In the previous chapter, we introduced the Swing text components, ignoring many of the details in order to simplify the introduction. In this chapter,[46] 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.

The Document Model

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.

High-level Document class diagram

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 Element s that describe the structural pieces of a Document, such as paragraphs or sections of specially formatted text (e.g., italics). Elements are made up of child Elements, forming a tree with a “root” Element as the base and arbitrary levels of child Elements below ...

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