Java Reference
In-Depth Information
In lines 133 and 134, two TabStops are created at 200 and 350 pixels; they
become part of the TabSet for the JTextPane. Lines 138 through 141 set the style
and attributes for the tabs.
Lines 144 through 157 create the font style. First, a default style is assigned
in line 145. Next, that style is used to create a keyword, regular, in line 147. Then,
the font is set to SansSerif in line 148. Italic, bold, and large attributes are set in
lines 150, 153, and 156, respectively.
The following step enters code for the setTabsAndStyles() method.
To Code the setTabsAndStyles() Method
1. Enter the code shown in Figure 7-22 on the previous page.
TextPad displays the code for the setTabsAndStyles() method (Figure 7-23).
tab stops
created
tab style
methods
font style
methods
FIGURE 7-23
When another part of the program calls it, the setTabsAndStyles() method
will format the text pane with the appropriate tabs and styles.
The Document Class
The Document class creates a container for text serving as the model for Swing
text components. Rather than inserting text directly into a JTextPane, for exam-
ple, programmers sometimes will use a Document class to hold the text; this is
useful for appending and refreshing text-based Swing components. Table 7-10
displays some useful methods in the Document class.
 
Search WWH ::




Custom Search