Java Swing - O Reilly Chapter 19. (Hosting web) Text 101
Java Swing - O Reilly Chapter 19. Text 101 Swing provides an extensive collection of classes for working with text in user interfaces. In fact, there’s so much provided for working with text, Swing’s creators placed most of it into its own package: javax.swing.text . This package’s dozens of interfaces and classes (plus the five concrete component classes in javax.swing) provide a rich (and complex!) set of text-based models and components. Over the course of the next six chapters, we’ll cover each of these classes and interfaces in detail. Figure 19.1 shows a very high-level view of the structure of the Swing text components. The arrows in the figure can be read as “knows about,” or “uses.” Figure 19.1. High-level view of the Swing text framework The text content for any component is stored in a model object called a Document. Chapter 20, and Chapter 21, cover the complex Swing document model in considerable detail. This model allows you to represent highly structured text supporting multiple fonts and colors, and even embedded Icons and Components. Swing text components allow you to customize certain aspects of the look-and-feel without much work. This includes the creation of custom carets (cursor) and custom highlighting, as well as the definition of custom key bindings, allowing you to associate Actions with special key combinations. These features are covered in Chapter 22. As usual, each text component delegates its painting tasks to a UI delegate. Unlike the other Swing UI delegates, the TextUI relies heavily on a large number of additional classes that extend a common base class called View. These classes are responsible for the details of layout, including issues such as alignment and text wrapping. We’ll cover all of these classes in detail in Chapter 23. Finally, all of this is tied together by something called an EditorKit. EditorKits allow you to define how your documents will be input and output via streams, what view objects should be used in which situations, and what special actions your editor will support. EditorKits (and TextActions) are covered in Chapter 24. This may all seem a bit overwhelming. The good news is that despite all the complexity and power Swing’s text components provide, it’s still pretty simple to do most things. That is the focus of this chapter. Here, we’ll look at JTextComponent, the base class for all of the text components, and its five subclasses: JTextField, JPasswordField, JTextArea, JEditorPane, and JTextPane. We won’t cover the complex text model and view classes until later, but we’ll occasionally reference things you may want to investigate further in the upcoming chapters. In the case of JTextPane, we won’t cover the properties and methods of this class in this chapter, because they rely pretty heavily on the document model. Instead, we’ll just provide a brief overview and an example that shows how to do a few basic things that would be particularly difficult to do with the AWT text components. - 578
Check Tomcat Web Hosting services for best quality webspace to host your web application.