APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.swing

public Class ScrollPaneLayout

extends Object
implements LayoutManager, ScrollPaneConstants, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, javax.swing.ScrollPaneConstants, java.awt.LayoutManager
Known Direct Subclasses
javax.swing.ScrollPaneLayout.UIResource
Annotations
@SuppressWarnings:serial
Imports
javax.swing.border.*, java.awt.LayoutManager, .Component, .Container, .Rectangle, .Dimension, .Insets, java.io.Serializable

The layout manager used by JScrollPane. ScrollPaneLayout 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 java.beans.XMLEncoder.

Author
Hans Muller
Since
1.2
See Also
JScrollPane, JViewport

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
ScrollPaneLayout.UIResource

The UI resource version of ScrollPaneLayout.

Field Summary

Modifier and TypeField and 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.

Constructor Summary

AccessConstructor and Description
public
ScrollPaneLayout()

Constructs a ScrollPaneLayout.

Method Summary

Modifier and TypeMethod and Description
public void
addLayoutComponent(String
the component identifier
s
,
Component
the component to be added
c
)

Implements java.awt.LayoutManager.addLayoutComponent.

Adds the specified component to the layout.

protected Component

Returns:

the newC
addSingletonComponent
(Component
the Component to replace
oldC
,
Component
the Component to add
newC
)

Removes an existing component.

private void
adjustForHSB(boolean wantsHSB, Rectangle available, Rectangle hsbR, Insets vpbInsets)

Adjusts the Rectangle available based on if the horizontal scrollbar is needed (wantsHSB).

private void
adjustForVSB(boolean wantsVSB, Rectangle available, Rectangle vsbR, Insets vpbInsets, boolean leftToRight)

Adjusts the Rectangle available based on if the vertical scrollbar is needed (wantsVSB).

public JViewport

Returns:

the JViewport object that is the column header
getColumnHeader
()

Returns the JViewport object that is the column header.

public Component

Returns:

the Component at the specified corner, as defined in ScrollPaneConstants; if key is not one of the four corners, null is returned
getCorner
(String
the String specifying the corner
key
)

Returns the Component at the specified corner.

public JScrollBar

Returns:

the JScrollBar object that handles horizontal scrolling
getHorizontalScrollBar
()

Returns the JScrollBar object that handles horizontal scrolling.

public int

Returns:

an integer giving the display policy
getHorizontalScrollBarPolicy
()

Returns the horizontal scrollbar-display policy.

public JViewport

Returns:

the JViewport object that is the row header
getRowHeader
()

Returns the JViewport object that is the row header.

public JScrollBar

Returns:

the JScrollBar object that handles vertical scrolling
getVerticalScrollBar
()

Returns the JScrollBar object that handles vertical scrolling.

public int

Returns:

an integer giving the display policy
getVerticalScrollBarPolicy
()

Returns the vertical scrollbar-display policy.

public JViewport

Returns:

the JViewport object that displays the scrollable contents
getViewport
()

Returns the JViewport object that displays the scrollable contents.

public Rectangle

Returns:

the size and position of the viewport border
getViewportBorderBounds
(JScrollPane
an instance of the JScrollPane
scrollpane
)
Deprecated As of JDK version Swing1.1 replaced by JScrollPane.getViewportBorderBounds().

Returns the bounds of the border around the specified scroll pane's viewport.

public void
layoutContainer(Container
the Container to lay out
parent
)

Implements java.awt.LayoutManager.layoutContainer.

Lays out the scrollpane.

public Dimension

Returns:

a Dimension object specifying the minimum size
minimumLayoutSize
(Container
the Container that will be laid out
parent
)

Implements java.awt.LayoutManager.minimumLayoutSize.

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.

public Dimension

Returns:

a Dimension object specifying the preferred size of the viewport and any scrollbars
preferredLayoutSize
(Container
the Container that will be laid out
parent
)

Implements java.awt.LayoutManager.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.

public void
removeLayoutComponent(Component
the component to remove
c
)

Implements java.awt.LayoutManager.removeLayoutComponent.

Removes the specified component from the layout.

public void
setHorizontalScrollBarPolicy(int
an int giving the display policy
x
)

Sets the horizontal scrollbar-display policy.

public void
setVerticalScrollBarPolicy(int
an integer giving the display policy
x
)

Sets the vertical scrollbar-display policy.

public void
syncWithScrollPane(JScrollPane
an instance of the JScrollPane
sp
)

This method is invoked after the ScrollPaneLayout is set as the LayoutManager of a JScrollPane.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

colHeadback to summary
protected JViewport colHead

The column header child. Default is null.

See Also
JScrollPane#setColumnHeader
hsbback to summary
protected JScrollBar hsb

The scrollpane's horizontal scrollbar child. Default is a JScrollBar.

See Also
JScrollPane#setHorizontalScrollBar
hsbPolicyback to summary
protected int hsbPolicy

The display policy for the horizontal scrollbar. The default is ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED.

This field is obsolete, please use the JScrollPane field instead.

See Also
JScrollPane#setHorizontalScrollBarPolicy
lowerLeftback to summary
protected Component lowerLeft

The component to display in the lower left corner. Default is null.

See Also
JScrollPane#setCorner
lowerRightback to summary
protected Component lowerRight

The component to display in the lower right corner. Default is null.

See Also
JScrollPane#setCorner
rowHeadback to summary
protected JViewport rowHead

The row header child. Default is null.

See Also
JScrollPane#setRowHeader
upperLeftback to summary
protected Component upperLeft

The component to display in the upper left corner. Default is null.

See Also
JScrollPane#setCorner
upperRightback to summary
protected Component upperRight

The component to display in the upper right corner. Default is null.

See Also
JScrollPane#setCorner
viewportback to summary
protected JViewport viewport

The scrollpane's viewport child. Default is an empty JViewport.

See Also
JScrollPane#setViewport
vsbback to summary
protected JScrollBar vsb

The scrollpane's vertical scrollbar child. Default is a JScrollBar.

See Also
JScrollPane#setVerticalScrollBar
vsbPolicyback to summary
protected int vsbPolicy

The display policy for the vertical scrollbar. The default is ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED.

This field is obsolete, please use the JScrollPane field instead.

See Also
JScrollPane#setVerticalScrollBarPolicy

Constructor Detail

ScrollPaneLayoutback to summary
public ScrollPaneLayout()

Constructs a ScrollPaneLayout.

Method Detail

addLayoutComponentback to summary
public void addLayoutComponent(String s, Component c)

Implements java.awt.LayoutManager.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
Parameters
s:String

the component identifier

c:Component

the component to be added

Exceptions
IllegalArgumentException:
if s is an invalid key
addSingletonComponentback to summary
protected Component addSingletonComponent(Component oldC, Component newC)

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. If oldC is not equal to newC and is non-null, it will be removed from its parent.

Parameters
oldC:Component

the Component to replace

newC:Component

the Component to add

Returns:Component

the newC

adjustForHSBback to summary
private void adjustForHSB(boolean wantsHSB, Rectangle available, Rectangle hsbR, Insets vpbInsets)

Adjusts the Rectangle available based on if the horizontal scrollbar is needed (wantsHSB). The location of the hsb is updated in hsbR, and the viewport border insets (vpbInsets) are used to offset the hsb. This is only called when wantsHSB has changed, eg you shouldn't invoked adjustForHSB(true) twice.

adjustForVSBback to summary
private void adjustForVSB(boolean wantsVSB, Rectangle available, Rectangle vsbR, Insets vpbInsets, boolean leftToRight)

Adjusts the Rectangle available based on if the vertical scrollbar is needed (wantsVSB). The location of the vsb is updated in vsbR, and the viewport border insets (vpbInsets) are used to offset the vsb. This is only called when wantsVSB has changed, eg you shouldn't invoke adjustForVSB(true) twice.

getColumnHeaderback to summary
public JViewport getColumnHeader()

Returns the JViewport object that is the column header.

Returns:JViewport

the JViewport object that is the column header

See Also
JScrollPane#getColumnHeader
getCornerback to summary
public Component getCorner(String key)

Returns the Component at the specified corner.

Parameters
key:String

the String specifying the corner

Returns:Component

the Component at the specified corner, as defined in ScrollPaneConstants; if key is not one of the four corners, null is returned

See Also
JScrollPane#getCorner
getHorizontalScrollBarback to summary
public JScrollBar getHorizontalScrollBar()

Returns the JScrollBar object that handles horizontal scrolling.

Returns:JScrollBar

the JScrollBar object that handles horizontal scrolling

See Also
JScrollPane#getHorizontalScrollBar
getHorizontalScrollBarPolicyback to summary
public int getHorizontalScrollBarPolicy()

Returns the horizontal scrollbar-display policy.

Returns:int

an integer giving the display policy

See Also
setHorizontalScrollBarPolicy
getRowHeaderback to summary
public JViewport getRowHeader()

Returns the JViewport object that is the row header.

Returns:JViewport

the JViewport object that is the row header

See Also
JScrollPane#getRowHeader
getVerticalScrollBarback to summary
public JScrollBar getVerticalScrollBar()

Returns the JScrollBar object that handles vertical scrolling.

Returns:JScrollBar

the JScrollBar object that handles vertical scrolling

See Also
JScrollPane#getVerticalScrollBar
getVerticalScrollBarPolicyback to summary
public int getVerticalScrollBarPolicy()

Returns the vertical scrollbar-display policy.

Returns:int

an integer giving the display policy

See Also
setVerticalScrollBarPolicy
getViewportback to summary
public JViewport getViewport()

Returns the JViewport object that displays the scrollable contents.

Returns:JViewport

the JViewport object that displays the scrollable contents

See Also
JScrollPane#getViewport
getViewportBorderBoundsback to summary
public Rectangle getViewportBorderBounds(JScrollPane scrollpane)

Deprecated

As of JDK version Swing1.1 replaced by JScrollPane.getViewportBorderBounds().

Returns the bounds of the border around the specified scroll pane's viewport.

Parameters
scrollpane:JScrollPane

an instance of the JScrollPane

Returns:Rectangle

the size and position of the viewport border

Annotations
@Deprecated
layoutContainerback to summary
public void layoutContainer(Container parent)

Implements java.awt.LayoutManager.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.
Parameters
parent:Container

the Container to lay out

minimumLayoutSizeback to summary
public Dimension minimumLayoutSize(Container parent)

Implements java.awt.LayoutManager.minimumLayoutSize.

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.

Parameters
parent:Container

the Container that will be laid out

Returns:Dimension

a Dimension object specifying the minimum size

preferredLayoutSizeback to summary
public Dimension preferredLayoutSize(Container parent)

Implements java.awt.LayoutManager.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.

Parameters
parent:Container

the Container that will be laid out

Returns:Dimension

a Dimension object specifying the preferred size of the viewport and any scrollbars

See Also
ViewportLayout, LayoutManager
removeLayoutComponentback to summary
public void removeLayoutComponent(Component c)

Implements java.awt.LayoutManager.removeLayoutComponent.

Removes the specified component from the layout.

Parameters
c:Component

the component to remove

setHorizontalScrollBarPolicyback to summary
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 the 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:int

an int giving the display policy

Exceptions
IllegalArgumentException:
if x is not a valid horizontal scrollbar policy, as listed above
setVerticalScrollBarPolicyback to summary
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 the 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:int

an integer giving the display policy

Exceptions
IllegalArgumentException:
if x is an invalid vertical scroll bar policy, as listed above
syncWithScrollPaneback to summary
public void syncWithScrollPane(JScrollPane sp)

This method is invoked after the ScrollPaneLayout is set as the LayoutManager of a JScrollPane. It initializes all of the internal fields that are ordinarily set by addLayoutComponent. For example:

ScrollPaneLayout mySPLayout = new ScrollPanelLayout() {
    public void layoutContainer(Container p) {
        super.layoutContainer(p);
        // do some extra work here ...
    }
};
scrollpane.setLayout(mySPLayout):
Parameters
sp:JScrollPane

an instance of the JScrollPane

javax.swing back to summary

public Class ScrollPaneLayout.UIResource

extends ScrollPaneLayout
implements UIResource
Class Inheritance
All Implemented Interfaces
javax.swing.plaf.UIResource

The UI resource version of ScrollPaneLayout.

Field Summary

Inherited from javax.swing.ScrollPaneLayout:
colHeadhsbhsbPolicylowerLeftlowerRightrowHeadupperLeftupperRightviewportvsbvsbPolicy

Constructor Summary

AccessConstructor and Description
public
UIResource()

Constructs a UIResource.

Method Summary

Inherited from javax.swing.ScrollPaneLayout:
addLayoutComponentaddSingletonComponentgetColumnHeadergetCornergetHorizontalScrollBargetHorizontalScrollBarPolicygetRowHeadergetVerticalScrollBargetVerticalScrollBarPolicygetViewportgetViewportBorderBoundslayoutContainerminimumLayoutSizepreferredLayoutSizeremoveLayoutComponentsetHorizontalScrollBarPolicysetVerticalScrollBarPolicysyncWithScrollPane

Constructor Detail

UIResourceback to summary
public UIResource()

Constructs a UIResource.