Class ScrollPaneLayout
java.lang.Object
javax.swing.ScrollPaneLayout
- All Implemented Interfaces:
LayoutManager, Serializable, ScrollPaneConstants
- Direct Known Subclasses:
ScrollPaneLayout.UIResource
public class ScrollPaneLayout
extends Object
implements LayoutManager, ScrollPaneConstants, Serializable
The layout manager used by
JScrollPane
.
JScrollPaneLayout
is
responsible for nine components: a viewport, two scrollbars,
a row header, a column header, and four "corner" components.
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 JavaBeans
has been added to the java.beans
package.
Please see XMLEncoder
.
- Since:
- 1.2
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
The UI resource version ofScrollPaneLayout
. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected JViewport
The column header child.protected JScrollBar
The scrollpane's horizontal scrollbar child.protected int
The display policy for the horizontal scrollbar.protected Component
The component to display in the lower left corner.protected Component
The component to display in the lower right corner.protected JViewport
The row header child.protected Component
The component to display in the upper left corner.protected Component
The component to display in the upper right corner.protected JViewport
The scrollpane's viewport child.protected JScrollBar
The scrollpane's vertical scrollbar child.protected int
The display policy for the vertical scrollbar.Fields declared in interface ScrollPaneConstants
COLUMN_HEADER, HORIZONTAL_SCROLLBAR, HORIZONTAL_SCROLLBAR_ALWAYS, HORIZONTAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_NEVER, HORIZONTAL_SCROLLBAR_POLICY, LOWER_LEADING_CORNER, LOWER_LEFT_CORNER, LOWER_RIGHT_CORNER, LOWER_TRAILING_CORNER, ROW_HEADER, UPPER_LEADING_CORNER, UPPER_LEFT_CORNER, UPPER_RIGHT_CORNER, UPPER_TRAILING_CORNER, VERTICAL_SCROLLBAR, VERTICAL_SCROLLBAR_ALWAYS, VERTICAL_SCROLLBAR_AS_NEEDED, VERTICAL_SCROLLBAR_NEVER, VERTICAL_SCROLLBAR_POLICY, VIEWPORT
Modifier and TypeFieldDescriptionstatic final String
Identifies the area at the top the viewport between the upper left corner and the upper right corner.static final String
Identifies a horizontal scrollbar.static final int
Used to set the horizontal scroll bar policy so that horizontal scrollbars are always displayed.static final int
Used to set the horizontal scroll bar policy so that horizontal scrollbars are displayed only when needed.static final int
Used to set the horizontal scroll bar policy so that horizontal scrollbars are never displayed.static final String
Identifies the horizontal scroll bar policy property.static final String
Identifies the lower leading edge corner of the viewport.static final String
Identifies the lower left corner of the viewport.static final String
Identifies the lower right corner of the viewport.static final String
Identifies the lower trailing edge corner of the viewport.static final String
Identifies the area along the left side of the viewport between the upper left corner and the lower left corner.static final String
Identifies the upper leading edge corner of the viewport.static final String
Identifies the upper left corner of the viewport.static final String
Identifies the upper right corner of the viewport.static final String
Identifies the upper trailing edge corner of the viewport.static final String
Identifies a vertical scrollbar.static final int
Used to set the vertical scroll bar policy so that vertical scrollbars are always displayed.static final int
Used to set the vertical scroll bar policy so that vertical scrollbars are displayed only when needed.static final int
Used to set the vertical scroll bar policy so that vertical scrollbars are never displayed.static final String
Identifies the vertical scroll bar policy property.static final String
Identifies a "viewport" or display area, within which scrolled contents are visible. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds the specified component to the layout.protected Component
addSingletonComponent
(Component oldC, Component newC) Removes an existing component.Returns theJViewport
object that is the column header.Returns theComponent
at the specified corner.Returns theJScrollBar
object that handles horizontal scrolling.int
Returns the horizontal scrollbar-display policy.Returns theJViewport
object that is the row header.Returns theJScrollBar
object that handles vertical scrolling.int
Returns the vertical scrollbar-display policy.Returns theJViewport
object that displays the scrollable contents.getViewportBorderBounds
(JScrollPane scrollpane) Deprecated.void
layoutContainer
(Container parent) Lays out the scrollpane.minimumLayoutSize
(Container parent) The minimum size of aScrollPane
is the size of the insets plus minimum size of the viewport, plus the scrollpane's viewportBorder insets, plus the minimum size of the visible headers, plus the minimum size of the scrollbars whose displayPolicy isn't NEVER.preferredLayoutSize
(Container parent) The preferred size of aScrollPane
is the size of the insets, plus the preferred size of the viewport, plus the preferred size of the visible headers, plus the preferred size of the scrollbars that will appear given the current view and the current scrollbar displayPolicies.void
Removes the specified component from the layout.void
setHorizontalScrollBarPolicy
(int x) Sets the horizontal scrollbar-display policy.void
setVerticalScrollBarPolicy
(int x) Sets the vertical scrollbar-display policy.void
This method is invoked after the ScrollPaneLayout is set as the LayoutManager of aJScrollPane
.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Modifier and TypeMethodDescriptionprotected Object
clone()
Creates and returns a copy of this object.boolean
Indicates whether some other object is "equal to" this one.protected void
finalize()
Deprecated, for removal: This API element is subject to removal in a future version.Finalization is deprecated and subject to removal in a future release.final Class
<?> getClass()
Returns the runtime class of thisObject
.int
hashCode()
Returns a hash code value for this object.final void
notify()
Wakes up a single thread that is waiting on this object's monitor.final void
Wakes up all threads that are waiting on this object's monitor.toString()
Returns a string representation of the object.final void
wait()
Causes the current thread to wait until it is awakened, typically by being notified or interrupted.final void
wait
(long timeoutMillis) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.final void
wait
(long timeoutMillis, int nanos) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
-
Field Details
-
viewport
The scrollpane's viewport child. Default is an emptyJViewport
.- See Also:
-
vsb
The scrollpane's vertical scrollbar child. Default is aJScrollBar
.- See Also:
-
hsb
The scrollpane's horizontal scrollbar child. Default is aJScrollBar
.- See Also:
-
rowHead
-
colHead
-
lowerLeft
The component to display in the lower left corner. Default isnull
.- See Also:
-
lowerRight
The component to display in the lower right corner. Default isnull
.- See Also:
-
upperLeft
The component to display in the upper left corner. Default isnull
.- See Also:
-
upperRight
The component to display in the upper right corner. Default isnull
.- See Also:
-
vsbPolicy
protected int vsbPolicyThe display policy for the vertical scrollbar. The default isScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED
.This field is obsolete, please use the
JScrollPane
field instead.- See Also:
-
hsbPolicy
protected int hsbPolicyThe display policy for the horizontal scrollbar. The default isScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED
.This field is obsolete, please use the
JScrollPane
field instead.- See Also:
-
-
Constructor Details
-
ScrollPaneLayout
public ScrollPaneLayout()Constructs aScrollPaneLayout
.
-
-
Method Details
-
syncWithScrollPane
This method is invoked after the ScrollPaneLayout is set as the LayoutManager of aJScrollPane
. It initializes all of the internal fields that are ordinarily set byaddLayoutComponent
. For example:ScrollPaneLayout mySPLayout = new ScrollPanelLayout() { public void layoutContainer(Container p) { super.layoutContainer(p); // do some extra work here ... } }; scrollpane.setLayout(mySPLayout):
- Parameters:
sp
- an instance of theJScrollPane
-
addSingletonComponent
Removes an existing component. When a new component, such as the left corner, or vertical scrollbar, is added, the old one, if it exists, must be removed.This method returns
newC
. IfoldC
is not equal tonewC
and is non-null
, it will be removed from its parent.- Parameters:
oldC
- theComponent
to replacenewC
- theComponent
to add- Returns:
- the
newC
-
addLayoutComponent
Adds the specified component to the layout. The layout is identified using one of:- ScrollPaneConstants.VIEWPORT
- ScrollPaneConstants.VERTICAL_SCROLLBAR
- ScrollPaneConstants.HORIZONTAL_SCROLLBAR
- ScrollPaneConstants.ROW_HEADER
- ScrollPaneConstants.COLUMN_HEADER
- ScrollPaneConstants.LOWER_LEFT_CORNER
- ScrollPaneConstants.LOWER_RIGHT_CORNER
- ScrollPaneConstants.UPPER_LEFT_CORNER
- ScrollPaneConstants.UPPER_RIGHT_CORNER
- Specified by:
addLayoutComponent
in interfaceLayoutManager
- Parameters:
s
- the component identifierc
- the component to be added- Throws:
IllegalArgumentException
- ifs
is an invalid key
-
removeLayoutComponent
Removes the specified component from the layout.- Specified by:
removeLayoutComponent
in interfaceLayoutManager
- Parameters:
c
- the component to remove
-
getVerticalScrollBarPolicy
public int getVerticalScrollBarPolicy()Returns the vertical scrollbar-display policy.- Returns:
- an integer giving the display policy
- See Also:
-
setVerticalScrollBarPolicy
public void setVerticalScrollBarPolicy(int x) Sets the vertical scrollbar-display policy. The options are:- ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED
- ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER
- ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS
JScrollPane
version of this method. It only exists for backwards compatibility with the Swing 1.0.2 (and earlier) versions of this class.- Parameters:
x
- an integer giving the display policy- Throws:
IllegalArgumentException
- ifx
is an invalid vertical scroll bar policy, as listed above
-
getHorizontalScrollBarPolicy
public int getHorizontalScrollBarPolicy()Returns the horizontal scrollbar-display policy.- Returns:
- an integer giving the display policy
- See Also:
-
setHorizontalScrollBarPolicy
public void setHorizontalScrollBarPolicy(int x) Sets the horizontal scrollbar-display policy. The options are:- ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED
- ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER
- ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS
JScrollPane
version of this method. It only exists for backwards compatibility with the Swing 1.0.2 (and earlier) versions of this class.- Parameters:
x
- an int giving the display policy- Throws:
IllegalArgumentException
- ifx
is not a valid horizontal scrollbar policy, as listed above
-
getViewport
Returns theJViewport
object that displays the scrollable contents.- Returns:
- the
JViewport
object that displays the scrollable contents - See Also:
-
getHorizontalScrollBar
Returns theJScrollBar
object that handles horizontal scrolling.- Returns:
- the
JScrollBar
object that handles horizontal scrolling - See Also:
-
getVerticalScrollBar
Returns theJScrollBar
object that handles vertical scrolling.- Returns:
- the
JScrollBar
object that handles vertical scrolling - See Also:
-
getRowHeader
Returns theJViewport
object that is the row header.- Returns:
- the
JViewport
object that is the row header - See Also:
-
getColumnHeader
Returns theJViewport
object that is the column header.- Returns:
- the
JViewport
object that is the column header - See Also:
-
getCorner
Returns theComponent
at the specified corner.- Parameters:
key
- theString
specifying the corner- Returns:
- the
Component
at the specified corner, as defined inScrollPaneConstants
; ifkey
is not one of the four corners,null
is returned - See Also:
-
preferredLayoutSize
The preferred size of aScrollPane
is the size of the insets, plus the preferred size of the viewport, plus the preferred size of the visible headers, plus the preferred size of the scrollbars that will appear given the current view and the current scrollbar displayPolicies.Note that the rowHeader is calculated as part of the preferred width and the colHeader is calculated as part of the preferred size.
- Specified by:
preferredLayoutSize
in interfaceLayoutManager
- Parameters:
parent
- theContainer
that will be laid out- Returns:
- a
Dimension
object specifying the preferred size of the viewport and any scrollbars - See Also:
-
minimumLayoutSize
The minimum size of aScrollPane
is the size of the insets plus minimum size of the viewport, plus the scrollpane's viewportBorder insets, plus the minimum size of the visible headers, plus the minimum size of the scrollbars whose displayPolicy isn't NEVER.- Specified by:
minimumLayoutSize
in interfaceLayoutManager
- Parameters:
parent
- theContainer
that will be laid out- Returns:
- a
Dimension
object specifying the minimum size - See Also:
-
layoutContainer
Lays out the scrollpane. The positioning of components depends on the following constraints:- The row header, if present and visible, gets its preferred width and the viewport's height.
- The column header, if present and visible, gets its preferred height and the viewport's width.
- If a vertical scrollbar is needed, i.e. if the viewport's extent
height is smaller than its view height or if the
displayPolicy
is ALWAYS, it's treated like the row header with respect to its dimensions and is made visible. - If a horizontal scrollbar is needed, it is treated like the column header (see the paragraph above regarding the vertical scrollbar).
- If the scrollpane has a non-
null
viewportBorder
, then space is allocated for that. - The viewport gets the space available after accounting for the previous constraints.
- The corner components, if provided, are aligned with the ends of the scrollbars and headers. If there is a vertical scrollbar, the right corners appear; if there is a horizontal scrollbar, the lower corners appear; a row header gets left corners, and a column header gets upper corners.
- Specified by:
layoutContainer
in interfaceLayoutManager
- Parameters:
parent
- theContainer
to lay out
-
getViewportBorderBounds
Deprecated.As of JDK version Swing1.1 replaced byJScrollPane.getViewportBorderBounds()
.Returns the bounds of the border around the specified scroll pane's viewport.- Parameters:
scrollpane
- an instance of theJScrollPane
- Returns:
- the size and position of the viewport border
-
JScrollPane.getViewportBorderBounds()
.