ScrollPaneLayout (Java SE 15 & JDK 15) (original) (raw)
All Implemented Interfaces:
[LayoutManager](../../java/awt/LayoutManager.html "interface in java.awt")
, [Serializable](../../../java.base/java/io/Serializable.html "interface in java.io")
, [ScrollPaneConstants](ScrollPaneConstants.html "interface in javax.swing")
Direct Known Subclasses:
[ScrollPaneLayout.UIResource](ScrollPaneLayout.UIResource.html "class in javax.swing")
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 Classes
Modifier and Type | Class | Description |
---|---|---|
static class | ScrollPaneLayout.UIResource | The UI resource version of ScrollPaneLayout. |
Field Summary
Fields
Modifier and Type | Field | Description |
---|---|---|
protected JViewport | colHead | The column header child. |
protected JScrollBar | hsb | The scrollpane's horizontal scrollbar child. |
protected int | hsbPolicy | 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 | rowHead | 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 JViewport | viewport | The scrollpane's viewport child. |
protected JScrollBar | vsb | The scrollpane's vertical scrollbar child. |
protected int | vsbPolicy | The display policy for the vertical scrollbar. |
Fields declared in interface javax.swing.ScrollPaneConstants
[COLUMN_HEADER](ScrollPaneConstants.html#COLUMN%5FHEADER), [HORIZONTAL_SCROLLBAR](ScrollPaneConstants.html#HORIZONTAL%5FSCROLLBAR), [HORIZONTAL_SCROLLBAR_ALWAYS](ScrollPaneConstants.html#HORIZONTAL%5FSCROLLBAR%5FALWAYS), [HORIZONTAL_SCROLLBAR_AS_NEEDED](ScrollPaneConstants.html#HORIZONTAL%5FSCROLLBAR%5FAS%5FNEEDED), [HORIZONTAL_SCROLLBAR_NEVER](ScrollPaneConstants.html#HORIZONTAL%5FSCROLLBAR%5FNEVER), [HORIZONTAL_SCROLLBAR_POLICY](ScrollPaneConstants.html#HORIZONTAL%5FSCROLLBAR%5FPOLICY), [LOWER_LEADING_CORNER](ScrollPaneConstants.html#LOWER%5FLEADING%5FCORNER), [LOWER_LEFT_CORNER](ScrollPaneConstants.html#LOWER%5FLEFT%5FCORNER), [LOWER_RIGHT_CORNER](ScrollPaneConstants.html#LOWER%5FRIGHT%5FCORNER), [LOWER_TRAILING_CORNER](ScrollPaneConstants.html#LOWER%5FTRAILING%5FCORNER), [ROW_HEADER](ScrollPaneConstants.html#ROW%5FHEADER), [UPPER_LEADING_CORNER](ScrollPaneConstants.html#UPPER%5FLEADING%5FCORNER), [UPPER_LEFT_CORNER](ScrollPaneConstants.html#UPPER%5FLEFT%5FCORNER), [UPPER_RIGHT_CORNER](ScrollPaneConstants.html#UPPER%5FRIGHT%5FCORNER), [UPPER_TRAILING_CORNER](ScrollPaneConstants.html#UPPER%5FTRAILING%5FCORNER), [VERTICAL_SCROLLBAR](ScrollPaneConstants.html#VERTICAL%5FSCROLLBAR), [VERTICAL_SCROLLBAR_ALWAYS](ScrollPaneConstants.html#VERTICAL%5FSCROLLBAR%5FALWAYS), [VERTICAL_SCROLLBAR_AS_NEEDED](ScrollPaneConstants.html#VERTICAL%5FSCROLLBAR%5FAS%5FNEEDED), [VERTICAL_SCROLLBAR_NEVER](ScrollPaneConstants.html#VERTICAL%5FSCROLLBAR%5FNEVER), [VERTICAL_SCROLLBAR_POLICY](ScrollPaneConstants.html#VERTICAL%5FSCROLLBAR%5FPOLICY), [VIEWPORT](ScrollPaneConstants.html#VIEWPORT)
Constructor Summary
Constructors
Constructor | Description |
---|---|
ScrollPaneLayout() |
Method Summary
Modifier and Type | Method | Description |
---|---|---|
void | addLayoutComponent(String s,Component c) | Adds the specified component to the layout. |
protected Component | addSingletonComponent(Component oldC,Component newC) | Removes an existing component. |
JViewport | getColumnHeader() | Returns the JViewport object that is the column header. |
Component | getCorner(String key) | Returns the Component at the specified corner. |
JScrollBar | getHorizontalScrollBar() | Returns the JScrollBar object that handles horizontal scrolling. |
int | getHorizontalScrollBarPolicy() | Returns the horizontal scrollbar-display policy. |
JViewport | getRowHeader() | Returns the JViewport object that is the row header. |
JScrollBar | getVerticalScrollBar() | Returns the JScrollBar object that handles vertical scrolling. |
int | getVerticalScrollBarPolicy() | Returns the vertical scrollbar-display policy. |
JViewport | getViewport() | Returns the JViewport object that displays the scrollable contents. |
Rectangle | getViewportBorderBounds(JScrollPane scrollpane) | Deprecated. |
void | layoutContainer(Container parent) | Lays out the scrollpane. |
Dimension | minimumLayoutSize(Container parent) | The minimum size of a ScrollPane 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. |
Dimension | preferredLayoutSize(Container parent) | The preferred size of a ScrollPane 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 | removeLayoutComponent(Component c) | 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 | syncWithScrollPane(JScrollPane sp) | This method is invoked after the ScrollPaneLayout is set as the LayoutManager of a JScrollPane. |
Methods declared in class java.lang.Object
[clone](../../../java.base/java/lang/Object.html#clone%28%29), [equals](../../../java.base/java/lang/Object.html#equals%28java.lang.Object%29), [finalize](../../../java.base/java/lang/Object.html#finalize%28%29), [getClass](../../../java.base/java/lang/Object.html#getClass%28%29), [hashCode](../../../java.base/java/lang/Object.html#hashCode%28%29), [notify](../../../java.base/java/lang/Object.html#notify%28%29), [notifyAll](../../../java.base/java/lang/Object.html#notifyAll%28%29), [toString](../../../java.base/java/lang/Object.html#toString%28%29), [wait](../../../java.base/java/lang/Object.html#wait%28%29), [wait](../../../java.base/java/lang/Object.html#wait%28long%29), [wait](../../../java.base/java/lang/Object.html#wait%28long,int%29)
Field Details
viewport
The scrollpane's viewport child. Default is an empty
JViewport
.
See Also:
JScrollPane.setViewport(javax.swing.JViewport)vsb
The scrollpane's vertical scrollbar child. Default is a
JScrollBar
.
See Also:
JScrollPane.setVerticalScrollBar(javax.swing.JScrollBar)hsb
The scrollpane's horizontal scrollbar child. Default is a
JScrollBar
.
See Also:
JScrollPane.setHorizontalScrollBar(javax.swing.JScrollBar)rowHead
The row header child. Default is
null
.
See Also:
JScrollPane.setRowHeader(javax.swing.JViewport)colHead
The column header child. Default is
null
.
See Also:
JScrollPane.setColumnHeader(javax.swing.JViewport)lowerLeft
The component to display in the lower left corner. Default is
null
.
See Also:
JScrollPane.setCorner(java.lang.String, java.awt.Component)lowerRight
The component to display in the lower right corner. Default is
null
.
See Also:
JScrollPane.setCorner(java.lang.String, java.awt.Component)upperLeft
The component to display in the upper left corner. Default is
null
.
See Also:
JScrollPane.setCorner(java.lang.String, java.awt.Component)upperRight
The component to display in the upper right corner. Default is
null
.
See Also:
JScrollPane.setCorner(java.lang.String, java.awt.Component)vsbPolicy
protected int vsbPolicy
The display policy for the vertical scrollbar. The default isScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED
.
This field is obsolete, please use theJScrollPane
field instead.
See Also:
JScrollPane.setVerticalScrollBarPolicy(int)hsbPolicy
protected int hsbPolicy
The display policy for the horizontal scrollbar. The default isScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED
.
This field is obsolete, please use theJScrollPane
field instead.
See Also:
JScrollPane.setHorizontalScrollBarPolicy(int)Constructor Details
ScrollPaneLayout
public ScrollPaneLayout()
Method Details
syncWithScrollPane
public void syncWithScrollPane(JScrollPane sp)
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 returnsnewC
. IfoldC
is not equal tonewC
and is non-null
, it will be removed from its parent.
Parameters:
oldC
- theComponent
to replace
newC
- theComponent
to add
Returns:
thenewC
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](../../java/awt/LayoutManager.html#addLayoutComponent%28java.lang.String,java.awt.Component%29)
in interface[LayoutManager](../../java/awt/LayoutManager.html "interface in java.awt")
Parameters:
s
- the component identifier
c
- the component to be added
Throws:
[IllegalArgumentException](../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang")
- ifs
is an invalid keyremoveLayoutComponent
public void removeLayoutComponent(Component c)
Removes the specified component from the layout.
Specified by:
[removeLayoutComponent](../../java/awt/LayoutManager.html#removeLayoutComponent%28java.awt.Component%29)
in interface[LayoutManager](../../java/awt/LayoutManager.html "interface in java.awt")
Parameters:
c
- the component to removegetVerticalScrollBarPolicy
public int getVerticalScrollBarPolicy()
Returns the vertical scrollbar-display policy.
Returns:
an integer giving the display policy
See Also:
setVerticalScrollBarPolicy(int)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
Note: Applications should use theJScrollPane
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](../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang")
- ifx
is an invalid vertical scroll bar policy, as listed abovegetHorizontalScrollBarPolicy
public int getHorizontalScrollBarPolicy()
Returns the horizontal scrollbar-display policy.
Returns:
an integer giving the display policy
See Also:
setHorizontalScrollBarPolicy(int)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
Note: Applications should use theJScrollPane
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](../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang")
- ifx
is not a valid horizontal scrollbar policy, as listed abovegetViewport
Returns the
JViewport
object that displays the scrollable contents.
Returns:
theJViewport
object that displays the scrollable contents
See Also:
JScrollPane.getViewport()getHorizontalScrollBar
public JScrollBar getHorizontalScrollBar()
Returns theJScrollBar
object that handles horizontal scrolling.
Returns:
theJScrollBar
object that handles horizontal scrolling
See Also:
JScrollPane.getHorizontalScrollBar()getVerticalScrollBar
Returns the
JScrollBar
object that handles vertical scrolling.
Returns:
theJScrollBar
object that handles vertical scrolling
See Also:
JScrollPane.getVerticalScrollBar()getColumnHeader
Returns the
JViewport
object that is the column header.
Returns:
theJViewport
object that is the column header
See Also:
JScrollPane.getColumnHeader()getCorner
Returns the
Component
at the specified corner.
Parameters:
key
- theString
specifying the corner
Returns:
theComponent
at the specified corner, as defined inScrollPaneConstants; ifkey
is not one of the four corners,null
is returned
See Also:
JScrollPane.getCorner(java.lang.String)preferredLayoutSize
The preferred size of a
ScrollPane
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](../../java/awt/LayoutManager.html#preferredLayoutSize%28java.awt.Container%29)
in interface[LayoutManager](../../java/awt/LayoutManager.html "interface in java.awt")
Parameters:
parent
- theContainer
that will be laid out
Returns:
aDimension
object specifying the preferred size of the viewport and any scrollbars
See Also:
ViewportLayout, LayoutManagerminimumLayoutSize
The minimum size of a
ScrollPane
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](../../java/awt/LayoutManager.html#minimumLayoutSize%28java.awt.Container%29)
in interface[LayoutManager](../../java/awt/LayoutManager.html "interface in java.awt")
Parameters:
parent
- theContainer
that will be laid out
Returns:
aDimension
object specifying the minimum size
See Also:
LayoutManager.preferredLayoutSize(java.awt.Container)layoutContainer
public void layoutContainer(Container parent)
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 thedisplayPolicy
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](../../java/awt/LayoutManager.html#layoutContainer%28java.awt.Container%29)
in interface[LayoutManager](../../java/awt/LayoutManager.html "interface in java.awt")
Parameters:
parent
- theContainer
to lay outgetViewportBorderBounds
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