|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object![]()
![]()
![]()
java.awt.Component
![]()
![]()
![]()
java.awt.Container
![]()
![]()
![]()
javax.swing.JComponent
![]()
![]()
![]()
javax.swing.JScrollPane
, MenuContainer
, Serializable
, Accessible
, ScrollPaneConstants

public class JScrollPane

, Accessible

Provides a scrollable view of a lightweight component.
A JScrollPane manages a viewport, optional
vertical and horizontal scroll bars, and optional row and
column heading viewports.
You can find task-oriented documentation of JScrollPane in
How to Use Scroll Panes,
a section in The Java Tutorial. Note that
JScrollPane does not support heavyweight components.
|
|
JViewport provides a window,
or "viewport" onto a data
source -- for example, a text file. That data source is the
"scrollable client" (aka data model) displayed by the
JViewport view.
A JScrollPane basically consists of JScrollBars,
a JViewport, and the wiring between them,
as shown in the diagram at right.
In addition to the scroll bars and viewport,
a JScrollPane can have a
column header and a row header. Each of these is a
JViewport object that
you specify with setRowHeaderView,
and setColumnHeaderView.
The column header viewport automatically scrolls left and right, tracking
the left-right scrolling of the main viewport.
(It never scrolls vertically, however.)
The row header acts in a similar fashion.
By default, the corners are empty.
You can put a component into a corner using
setCorner,
in case you there is some function or decoration you
would like to add to the scroll pane. The size of corner components is
entirely determined by the size of the headers and scroll bars that
surround them.
To add a border around the main viewport,
you can use setViewportBorder.
(Of course, you can also add a border around the whole scroll pane using
setBorder.)
A common operation to want to do is to set the background color that will
be used if the main viewport view is smaller than the viewport, or is
not opaque. This can be accomplished by setting the background color
of the viewport, via scrollPane.getViewport().setBackground().
The reason for setting the color of the viewport and not the scrollpane
is that by default JViewport is opaque
which, among other things, means it will completely fill
in its background using its background color. Therefore when
JScrollPane draws its background the viewport will
usually draw over it.
By default JScrollPane uses ScrollPaneLayout
to handle the layout of its child Components. ScrollPaneLayout
determines the size to make the viewport view in one of two ways:
Scrollable
a combination of getPreferredScrollableViewportSize,
getScrollableTracksViewportWidth and
getScrollableTracksViewportHeightis used, otherwise
getPreferredSize is used.
Warning:
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeansTM
has been added to the java.beans package.
Please see XMLEncoder
.
JScrollBar
,
JViewport
,
ScrollPaneLayout
,
Scrollable
,
Component.getPreferredSize()
,
setViewportView(java.awt.Component)
,
setRowHeaderView(java.awt.Component)
,
setColumnHeaderView(java.awt.Component)
,
setCorner(java.lang.String, java.awt.Component)
,
setViewportBorder(javax.swing.border.Border)
,
Serialized Form| Nested Class Summary | |
|---|---|
protected class |
JScrollPane.AccessibleJScrollPane
This class implements accessibility support for the JScrollPane class. |
protected class |
JScrollPane.ScrollBar
By default JScrollPane creates scrollbars
that are instances
of this class. |
Nested classes/interfaces inherited from class javax.swing.JComponent ![]() |
|---|
JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container ![]() |
|---|
Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component ![]() |
|---|
Component.AccessibleAWTComponent |
| Field Summary | |
|---|---|
protected JViewport |
columnHeader
The column header child. |
protected JScrollBar |
horizontalScrollBar
The scrollpane's horizontal scrollbar child. |
protected int |
horizontalScrollBarPolicy
The display policy for the horizontal scrollbar. |
protected Component |
lowerLeft
The component to display in the lower left corner. |
protected Component |
lowerRight
The component to display in the lower right corner. |
protected JViewport |
rowHeader
The row header child. |
protected Component |
upperLeft
The component to display in the upper left corner. |
protected Component |
upperRight
The component to display in the upper right corner. |
protected JScrollBar |
verticalScrollBar
The scrollpane's vertical scrollbar child. |
protected int |
verticalScrollBarPolicy
The display policy for the vertical scrollbar. |
protected JViewport |
viewport
The scrollpane's viewport child. |
Fields inherited from class javax.swing.JComponent ![]() |
|---|
accessibleContext |
Fields inherited from class java.awt.Component ![]() |
|---|
BOTTOM_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver ![]() |
|---|
ABORT |
| Constructor Summary | |
|---|---|
JScrollPane
Creates an empty (no viewport view) JScrollPane
where both horizontal and vertical scrollbars appear when needed. |
|
JScrollPane
Creates a JScrollPane that displays the
contents of the specified
component, where both horizontal and vertical scrollbars appear
whenever the component's contents are larger than the view. |
|
JScrollPane
Creates a JScrollPane that displays the view
component in a viewport
whose view position can be controlled with a pair of scrollbars. |
|
JScrollPane
Creates an empty (no viewport view) JScrollPane
with specified
scrollbar policies. |
|
| Method Summary | |
|---|---|
JScrollBar |
createHorizontalScrollBar
Returns a JScrollPane.ScrollBar by default. |
JScrollBar |
createVerticalScrollBar
Returns a JScrollPane.ScrollBar by default. |
protected JViewport |
createViewport
Returns a new JViewport by default. |
AccessibleContext |
getAccessibleContext
Gets the AccessibleContext associated with this JScrollPane. |
JViewport |
getColumnHeader
Returns the column header. |
Component |
getCorner
Returns the component at the specified corner. |
JScrollBar |
getHorizontalScrollBar
Returns the horizontal scroll bar that controls the viewport's horizontal view position. |
int |
getHorizontalScrollBarPolicy
Returns the horizontal scroll bar policy value. |
JViewport |
getRowHeader
Returns the row header. |
ScrollPaneUI |
getUI
Returns the look and feel (L&F) object that renders this component. |
String |
getUIClassID
Returns the suffix used to construct the name of the L&F class used to render this component. |
JScrollBar |
getVerticalScrollBar
Returns the vertical scroll bar that controls the viewports vertical view position. |
int |
getVerticalScrollBarPolicy
Returns the vertical scroll bar policy value. |
JViewport |
getViewport
Returns the current JViewport. |
Border |
getViewportBorder
Returns the Border object that surrounds the viewport. |
Rectangle |
getViewportBorderBounds
Returns the bounds of the viewport's border. |
boolean |
isValidateRoot
Overridden to return true so that any calls to revalidate
on any descendants of this JScrollPane will cause the
entire tree beginning with this JScrollPane to be
validated. |
boolean |
isWheelScrollingEnabled
Indicates whether or not scrolling will take place in response to the mouse wheel. |
protected String |
paramString
Returns a string representation of this JScrollPane. |
void |
setColumnHeader
Removes the old columnHeader, if it exists. |
void |
setColumnHeaderView
Creates a column-header viewport if necessary, sets its view, and then adds the column-header viewport to the scrollpane. |
void |
setComponentOrientation
Sets the orientation for the vertical and horizontal scrollbars as determined by the ComponentOrientation argument. |
void |
setCorner
Adds a child that will appear in one of the scroll panes corners, if there's room. |
void |
setHorizontalScrollBar
Adds the scrollbar that controls the viewport's horizontal view position to the scrollpane. |
void |
setHorizontalScrollBarPolicy
Determines when the horizontal scrollbar appears in the scrollpane. |
void |
setLayout
Sets the layout manager for this JScrollPane. |
void |
setRowHeader
Removes the old rowHeader, if it exists. |
void |
setRowHeaderView |