The JTextComponent Class

The six concrete Swing text component classes have quite a bit in common. Consequently, they share a common base class, JTextComponent. Figure 19-2 shows the class hierarchy for the Swing text components. As you can see, the concrete text components are in the javax.swing package with the rest of the Swing component classes, but JTextComponent and all its supporting classes can be found in javax.swing.text.

The Swing text components

Figure 19-2. The Swing text components

JTextComponent is an abstract class that serves as the base class for all text-based Swing components. It defines a large number of properties and methods that apply to its subclasses. In this introductory chapter, we’ll pass quickly over many of these properties, as they require an understanding of the underlying model and view aspects of the text framework.

Properties

JTextComponent defines the properties and default values shown in Table 19-1. document is a reference to the Document model for the component, where the component’s content data is stored. (We’ll discuss the details of the Document interface in Chapter 22.) The UI property for all text components is a subclass of javax.swing.plaf.TextUI.

Table 19-1. JTextComponent properties

Property

Data type

get

is

set

Default value

accessibleContext o

AccessibleContext

·

  

AccessibleJTextComponent

actions

Action[]

·

  

From the UI’s EditorKit

caret b

Caret

·

 

·

null

caretColor

Get Java Swing, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.