I l@ve RuBoard |
![]() ![]() |
Chapter 21. Carets, Highlighters, and KeymapsLike some of the other Swing components (JTree, for example), the text components allow you to do a certain amount of customization without having to implement your own L&F. Certain aspects of these components' behavior and appearance can be modified directly through properties of JTextSCComponent. This chapter explains how to modify three such components: carets, highlighters, and keymaps. With the more flexible text components (JEditorPane and anything that extends it, including JTextPane), you can control the View objects created to render each Element of the Document model. In this chapter, we'll concentrate on the classes and interfaces related to modifying text components without dealing with View objects. Chapter 23 discusses custom View classes. JTextComponent has three UI-related properties that you can access and modify directly. These properties are defined by the following interfaces:
As you might expect, Swing provides default implementations of these interfaces. Figure 21-1 shows these classes and interfaces and the relationships between them. Note that each Caret and Highlighter is associated with a single JTextComponent (set by its install( ) method) while Keymap has no direct relation to any JTextComponent, and therefore can be used by multiple components. Figure 21-1. Caret, Highlighter, and Keymap class diagram![]() In the next few sections, we'll take a closer look at these interfaces as well as the default implementations for Caret and Highlighter. The default implementation of Keymap is an inner class of JTextComponent, which we can't subclass directly. When we get to that discussion, we'll see why we typically won't need to. ![]() |
I l@ve RuBoard |
![]() ![]() |