Java Reference
In-Depth Information
Besides enabling you to add the
JViewport
and two
JScrollBar
components for scrolling,
the
JScrollPane
allows you to provide two more
JViewport
objects for row and column headers
and four
Component
objects to display in the scroll pane corners. The placement of all these
components is managed by the
ScrollPaneLayout
manager, introduced in Chapter 10 and
described more fully here. The actual
JScrollBar
components used by
JScrollPane
are a
subclass of
JScrollBar
called
JScrollPane.ScrollBar
. They are used instead of the regular
JScrollBar
to properly handle scrolling the component inside the inner
JViewport
, when that
component implements the
Scrollable
interface.
To help you see how all the components fit within the
JScrollPane
, Figure 11-15 demon-
strates how the
ScrollPaneLayout
positions the various pieces.
UPPER_
LEFT_
CORNER
UPPER_
RIGHT_
CORNER
COLUMN_HEADER
VIEWPORT
LOWER_
LEFT_
CORNER
LOWER_
RIGHT_
CORNER
VERTICAL_SCROLLBAR
Figure 11-15.
ScrollPaneLayout regions
■
Caution
The
JScrollPane
component supports scrolling only lightweight components. You should not
add regular, heavyweight AWT components to the container.
Creating a JScrollPane
There are four
JScrollPane
constructors: