O'Reilly logo

Java Swing, 2nd Edition by Brian Cole, James Elliott, Marc Loy, Robert Eckstein, Dave Wood

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

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

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