Java Reference
In-Depth Information
Table 7-8
JScrollPane Methods
METHOD
PURPOSE
EXAMPLE
JScrollPane()
Accepts a Swing
myScrollPane = new
component as an argument
JScrollPane(myTextPane);
setVerticalScrollBarPolicy()
Determines when the
myScroll.setVerticalScrollBarPolicy
vertical scrollbar appears
(JScrollPane.
in the JScrollPane
VERTICAL_SCROLLBAR_ALWAYS);
setPreferredSize()
Sets the size of the
paneScrollPane.setPreferredSize(new
JScrollPane
Dimension(500,200));
setWheelScrollingEnabled()
Enables/disables scrolling
aScroll.setWheelScrollingEnabled(true);
in response to movement
of the mouse wheel
setViewportBorder()
Adds a border around the
dataScroll.setViewport(borderStyle);
viewport
The following step enters code for the createContentPane() method.
To Code the createContentPane() Method
1. Enter the code from Figure 7-19 on page 453.
TextPad displays the code for the createContentPane() method
(Figure 7-21).
JComboBox
methods
components added
to northPanel
code to create
display area
content pane
methods
content pane
returned to
calling method
FIGURE 7-21
The getContentPane() method from the Container class can be used with
JApplets or JFrames. When used with JApplets, the creation of the content pane
must take place in the init() method because the content pane connects its com-
ponents with the applet itself upon execution. With JFrames, the creation of the
content pane takes place in main() or in the constructor method.
 
Search WWH ::




Custom Search