Java Reference
In-Depth Information
Lines 98 through 100 add the three choices to the JComboBox. Line 101
adds the Action Listener.
Line 102 sets a tool tip for the JComboBox. The setToolTipText() method
creates a tool tip , which is a short descriptive message indicating the name of a
specific component or tool, or instructions on how to use it. Tool tips display
when the user moves the mouse over an object enabled with the setToolTipText()
method. Tool tip messages usually display in a highlighted box. When users move
the mouse over the JComboBox, the tool tip displays the words, Click the drop-
down arrow to display sort fields. Figure 7-20 shows the tool tip.
JComboBox
tool tip
FIGURE 7-20
Two JPanels also are created in this method: the northPanel and the
centerPanel. The northPanel, created in lines 105 through 108, will hold a JLabel
prompt and the JComboBox containing the sort fields. The northPanel uses a
FlowLayout. The centerPanel, created in lines 111 through 117, will display
information about the movies in a JTextPane declared previously. Line 112 calls
a user-defined method named setTabsAndStyles() to provide formatting
for the text pane. Line 113 calls another user-defined method named
addTextToTextPane() to add text. You will write the methods themselves later
in the chapter.
The centerPanel also contains a JScrollPane, constructed in line 114. A
JScrollPane facilitates a scrollable view of another Swing component, such as a
JTextPane. Java uses the term, viewport, to identify the portion of the text com-
ponent displayed within the JScrollPane at any given time. When screen space is
limited, programmers employ a JScrollPane to display a component that is large
or one whose size can change dynamically.
Table 7-8 displays some of the methods associated with JScrollPanes.
Line 115 uses the attribute, VERTICAL_SCROLLBAR_ALWAYS, as the
argument for the setVerticalScrollBarPolicy() method, so that vertical scroll bars
will display on the right of the JTextPane.
Line 116 sets the preferred size of the JScrollPane to 500 by 200 pixels as a
Dimension object is constructed. A Dimension is a logical size object, conceptu-
ally similar to a rectangle. The Dimension class encapsulates in a single object
the width and height of a component.
Finally, the getContentPane() method in line 120 constructs an instance of
the content pane. Its overall layout manager is BorderLayout, as specified in line
121. The JPanels are added to their respective regions, and the content pane is
returned to the calling method.
JAVA UPDATE J ava 2
J ava 2
v 5 . 0
v 5 . 0
A tool tip is different
from a pop-up display
or menu. In J2SE
version 5.0, program-
mers may use pop-ups
more freely because the
coding has been
simplified. The listener
interface that listens for
a right-click of the user's
mouse no longer has to
be installed, and
programmers do not
have to register the
appropriate key bind-
ings. A JPopupMenu()
method may be used
anywhere you want a
menu to display.
 
Search WWH ::




Custom Search