java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JScrollPane
All Implemented Interfaces:
ScrollPaneConstants, Accessible, HasGetTransferHandler, Serializable, MenuContainer, ImageObserver
Direct Known Subclasses:
SpeciesDataTable, JRCTable, StatusPanel, ProjectViewer
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 JScrollBar
s,
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.
Where two scroll bars meet, the row header meets the column header, or a scroll bar meets one of the headers, both components stop short of the corner, leaving a rectangular space which is, by default, empty. These spaces can potentially exist in any number of the four corners. In the previous diagram, the top right space is present and identified by the label "corner component".
Any number of these empty spaces can be replaced by using the
setCorner
method to add a component to a particular corner.
(Note: The same component cannot be added to multiple corners.)
This is useful if there's
some extra decoration or function you'd like to add to the scroll pane.
The size of each corner component is entirely determined by the size of the
headers and/or scroll bars that surround it.
A corner component will only be visible if there is an empty space in that
corner for it to exist in. For example, consider a component set into the
top right corner of a scroll pane with a column header. If the scroll pane's
vertical scrollbar is not present, perhaps because the view component hasn't
grown large enough to require it, then the corner component will not be
shown (since there is no empty space in that corner created by the meeting
of the header and vertical scroll bar). Forcing the scroll bar to always be
shown, using
setVerticalScrollBarPolicy(VERTICAL_SCROLLBAR_ALWAYS)
,
will ensure that the space for the corner component always exists.
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
getScrollableTracksViewportHeight
is used, otherwise
getPreferredSize
is used.
Warning: Swing is not thread safe. For more information see Swing's Threading Policy.
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 java.beans.XMLEncoder .
attribute
- : isContainer true
attribute: containerDelegate getViewport
description: A specialized container that manages a viewport, optional scrollbars and headersHans
- MullerNested Class Summary: | ||
---|---|---|
protected class | JScrollPane.ScrollBar | By default JScrollPane creates scrollbars
that are instances
of this class. Scrollbar overrides the
getUnitIncrement and getBlockIncrement
methods so that, if the viewport's view is a Scrollable ,
the view is asked to compute these values. Unless
the unit/block increment have been explicitly set.
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 |
protected class | JScrollPane.AccessibleJScrollPane | This class implements accessibility support for the
JScrollPane class. It provides an implementation of the
Java Accessibility API appropriate to scroll pane user-interface
elements.
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 |
Field Summary | ||
---|---|---|
protected int | verticalScrollBarPolicy | The display policy for the vertical scrollbar.
The default is
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED .
|
protected int | horizontalScrollBarPolicy | The display policy for the horizontal scrollbar.
The default is
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED .
|
protected JViewport | viewport | The scrollpane's viewport child. Default is an empty
JViewport .
|
protected JScrollBar | verticalScrollBar | The scrollpane's vertical scrollbar child.
Default is a JScrollBar .
|
protected JScrollBar | horizontalScrollBar | The scrollpane's horizontal scrollbar child.
Default is a JScrollBar .
|
protected JViewport | rowHeader | The row header child. Default is null .
|
protected JViewport | columnHeader | The column header child. Default is null .
|
protected Component | lowerLeft | The component to display in the lower left corner.
Default is null .
|
protected Component | lowerRight | The component to display in the lower right corner.
Default is null .
|
protected Component | upperLeft | The component to display in the upper left corner.
Default is null .
|
protected Component | upperRight | The component to display in the upper right corner.
Default is null .
|
Constructor: |
---|
JScrollPane
where both horizontal and vertical scrollbars appear when needed. |
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
with specified
scrollbar policies. The available policy settings are listed at
#setVerticalScrollBarPolicy and
#setHorizontalScrollBarPolicy .
|
JScrollPane that displays the view
component in a viewport
whose view position can be controlled with a pair of scrollbars.
The scrollbar policies specify when the scrollbars are displayed,
For example, if vsbPolicy is
VERTICAL_SCROLLBAR_AS_NEEDED
then the vertical scrollbar only appears if the view doesn't fit
vertically. The available policy settings are listed at
#setVerticalScrollBarPolicy and
#setHorizontalScrollBarPolicy .
|
Methods from java.lang.Object: |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method from javax.swing.JScrollPane Detail: |
---|
JScrollPane.ScrollBar by default.
Subclasses may override this method to force ScrollPaneUI
implementations to use a JScrollBar subclass.
Used by ScrollPaneUI implementations to
create the horizontal scrollbar. |
JScrollPane.ScrollBar by default. Subclasses
may override this method to force ScrollPaneUI
implementations to use a JScrollBar subclass.
Used by ScrollPaneUI implementations to create the
vertical scrollbar. |
JViewport by default.
Used to create the
viewport (as needed) in setViewportView ,
setRowHeaderView , and setColumnHeaderView .
Subclasses may override this method to return a subclass of
JViewport . |
|
|
key value specifying the corner is one of:
|
|
|
|
|
|
|
|
JViewport . |
Border object that surrounds the viewport. |
|
revalidate
on any descendants of this JScrollPane will cause the
entire tree beginning with this JScrollPane to be
validated. |
|
JScrollPane .
This method
is intended to be used only for debugging purposes, and the
content and format of the returned string may vary between
implementations. The returned string may be empty but may not
be null . |
null , syncs the x coordinate of its viewPosition
with the viewport (if there is one) and then adds it to the scroll pane.
Most applications will find it more convenient to use
|
JScrollPane scrollpane = new JScrollPane(); scrollpane.setViewportView(myBigComponentToScroll); scrollpane.setColumnHeaderView(myBigComponentsColumnHeader); |
ComponentOrientation argument. |
Although "corner" doesn't match any beans property
signature, |
JScrollPane creates
horizontal and vertical scrollbars by default. |
|
JScrollPane .
This method overrides setLayout in
java.awt.Container to ensure that only
LayoutManager s which
are subclasses of ScrollPaneLayout can be used in a
JScrollPane . If layout is non-null, this
will invoke syncWithScrollPane on it. |
null , syncs the y coordinate of its
viewPosition with
the viewport (if there is one) and then adds it to the scroll pane.
Most applications will find it more convenient to use
|
JScrollPane scrollpane = new JScrollPane(); scrollpane.setViewportView(myBigComponentToScroll); scrollpane.setRowHeaderView(myBigComponentsRowHeader); |
ScrollPaneUI object that provides the
look and feel (L&F) for this component. |
JScrollPane creates vertical and
horizontal scrollbars by default. |
|
Most applications will find it more convenient to use
|
JViewport doesn't support
the JComponent border property.
Similarly setting the JScrollPane s
viewport doesn't affect the viewportBorder property.
The default value of this property is computed by the look and feel implementation. |
JScrollPane
constructor
should use this method to specify the scrollable child that's going
to be displayed in the scrollpane. For example:
JScrollPane scrollpane = new JScrollPane(); scrollpane.setViewportView(myBigComponentToScroll);Applications should not add children directly to the scrollpane. |
|
ScrollPaneUI object with a version
from the current default look and feel.
To be called when the default look and feel changes. |