- 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 byJScrollPane.JScrollPaneLayoutis 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.beanspackage. Please seeXMLEncoder.- Since:
- 1.2
- See Also:
- JScrollPane,- JViewport, Serialized Form
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classScrollPaneLayout.UIResourceThe UI resource version ofScrollPaneLayout.
 - 
Field SummaryFields Modifier and Type Field Description protected JViewportcolHeadThe column header child.protected JScrollBarhsbThe scrollpane's horizontal scrollbar child.protected inthsbPolicyThe display policy for the horizontal scrollbar.protected ComponentlowerLeftThe component to display in the lower left corner.protected ComponentlowerRightThe component to display in the lower right corner.protected JViewportrowHeadThe row header child.protected ComponentupperLeftThe component to display in the upper left corner.protected ComponentupperRightThe component to display in the upper right corner.protected JViewportviewportThe scrollpane's viewport child.protected JScrollBarvsbThe scrollpane's vertical scrollbar child.protected intvsbPolicyThe display policy for the vertical scrollbar.- 
Fields declared in interface javax.swing.ScrollPaneConstantsCOLUMN_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
 
- 
 - 
Constructor SummaryConstructors Constructor Description ScrollPaneLayout()
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddLayoutComponent(String s, Component c)Adds the specified component to the layout.protected ComponentaddSingletonComponent(Component oldC, Component newC)Removes an existing component.JViewportgetColumnHeader()Returns theJViewportobject that is the column header.ComponentgetCorner(String key)Returns theComponentat the specified corner.JScrollBargetHorizontalScrollBar()Returns theJScrollBarobject that handles horizontal scrolling.intgetHorizontalScrollBarPolicy()Returns the horizontal scrollbar-display policy.JViewportgetRowHeader()Returns theJViewportobject that is the row header.JScrollBargetVerticalScrollBar()Returns theJScrollBarobject that handles vertical scrolling.intgetVerticalScrollBarPolicy()Returns the vertical scrollbar-display policy.JViewportgetViewport()Returns theJViewportobject that displays the scrollable contents.RectanglegetViewportBorderBounds(JScrollPane scrollpane)Deprecated.As of JDK version Swing1.1 replaced byJScrollPane.getViewportBorderBounds().voidlayoutContainer(Container parent)Lays out the scrollpane.DimensionminimumLayoutSize(Container parent)The minimum size of aScrollPaneis 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.DimensionpreferredLayoutSize(Container parent)The preferred size of aScrollPaneis 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.voidremoveLayoutComponent(Component c)Removes the specified component from the layout.voidsetHorizontalScrollBarPolicy(int x)Sets the horizontal scrollbar-display policy.voidsetVerticalScrollBarPolicy(int x)Sets the vertical scrollbar-display policy.voidsyncWithScrollPane(JScrollPane sp)This method is invoked after the ScrollPaneLayout is set as the LayoutManager of aJScrollPane.
 
- 
- 
- 
Field Detail- 
viewportprotected JViewport viewport The scrollpane's viewport child. Default is an emptyJViewport.
 - 
vsbprotected JScrollBar vsb The scrollpane's vertical scrollbar child. Default is aJScrollBar.
 - 
hsbprotected JScrollBar hsb The scrollpane's horizontal scrollbar child. Default is aJScrollBar.
 - 
rowHeadprotected JViewport rowHead The row header child. Default isnull.
 - 
colHeadprotected JViewport colHead The column header child. Default isnull.
 - 
lowerLeftprotected Component lowerLeft The component to display in the lower left corner. Default isnull.
 - 
lowerRightprotected Component lowerRight The component to display in the lower right corner. Default isnull.
 - 
upperLeftprotected Component upperLeft The component to display in the upper left corner. Default isnull.
 - 
upperRightprotected Component upperRight The component to display in the upper right corner. Default isnull.
 - 
vsbPolicyprotected int vsbPolicy The display policy for the vertical scrollbar. The default isScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED.This field is obsolete, please use the JScrollPanefield instead.
 - 
hsbPolicyprotected int hsbPolicy The display policy for the horizontal scrollbar. The default isScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED.This field is obsolete, please use the JScrollPanefield instead.
 
- 
 - 
Method Detail- 
syncWithScrollPanepublic 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 the- JScrollPane
 
 - 
addSingletonComponentprotected 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. IfoldCis not equal tonewCand is non-null, it will be removed from its parent.- Parameters:
- oldC- the- Componentto replace
- newC- the- Componentto add
- Returns:
- the newC
 
 - 
addLayoutComponentpublic void addLayoutComponent(String s, Component c) 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:
- addLayoutComponentin interface- LayoutManager
- Parameters:
- s- the component identifier
- c- the component to be added
- Throws:
- IllegalArgumentException- if- sis an invalid key
 
 - 
removeLayoutComponentpublic void removeLayoutComponent(Component c) Removes the specified component from the layout.- Specified by:
- removeLayoutComponentin interface- LayoutManager
- Parameters:
- c- the component to remove
 
 - 
getVerticalScrollBarPolicypublic int getVerticalScrollBarPolicy() Returns the vertical scrollbar-display policy.- Returns:
- an integer giving the display policy
- See Also:
- setVerticalScrollBarPolicy(int)
 
 - 
setVerticalScrollBarPolicypublic 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
 JScrollPaneversion 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- if- xis an invalid vertical scroll bar policy, as listed above
 
 - 
getHorizontalScrollBarPolicypublic int getHorizontalScrollBarPolicy() Returns the horizontal scrollbar-display policy.- Returns:
- an integer giving the display policy
- See Also:
- setHorizontalScrollBarPolicy(int)
 
 - 
setHorizontalScrollBarPolicypublic 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
 JScrollPaneversion 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- if- xis not a valid horizontal scrollbar policy, as listed above
 
 - 
getViewportpublic JViewport getViewport() Returns theJViewportobject that displays the scrollable contents.- Returns:
- the JViewportobject that displays the scrollable contents
- See Also:
- JScrollPane.getViewport()
 
 - 
getHorizontalScrollBarpublic JScrollBar getHorizontalScrollBar() Returns theJScrollBarobject that handles horizontal scrolling.- Returns:
- the JScrollBarobject that handles horizontal scrolling
- See Also:
- JScrollPane.getHorizontalScrollBar()
 
 - 
getVerticalScrollBarpublic JScrollBar getVerticalScrollBar() Returns theJScrollBarobject that handles vertical scrolling.- Returns:
- the JScrollBarobject that handles vertical scrolling
- See Also:
- JScrollPane.getVerticalScrollBar()
 
 - 
getRowHeaderpublic JViewport getRowHeader() Returns theJViewportobject that is the row header.- Returns:
- the JViewportobject that is the row header
- See Also:
- JScrollPane.getRowHeader()
 
 - 
getColumnHeaderpublic JViewport getColumnHeader() Returns theJViewportobject that is the column header.- Returns:
- the JViewportobject that is the column header
- See Also:
- JScrollPane.getColumnHeader()
 
 - 
getCornerpublic Component getCorner(String key) Returns theComponentat the specified corner.- Parameters:
- key- the- Stringspecifying the corner
- Returns:
- the Componentat the specified corner, as defined inScrollPaneConstants; ifkeyis not one of the four corners,nullis returned
- See Also:
- JScrollPane.getCorner(java.lang.String)
 
 - 
preferredLayoutSizepublic Dimension preferredLayoutSize(Container parent) The preferred size of aScrollPaneis 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:
- preferredLayoutSizein interface- LayoutManager
- Parameters:
- parent- the- Containerthat will be laid out
- Returns:
- a Dimensionobject specifying the preferred size of the viewport and any scrollbars
- See Also:
- ViewportLayout,- LayoutManager
 
 - 
minimumLayoutSizepublic Dimension minimumLayoutSize(Container parent) The minimum size of aScrollPaneis 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:
- minimumLayoutSizein interface- LayoutManager
- Parameters:
- parent- the- Containerthat will be laid out
- Returns:
- a Dimensionobject specifying the minimum size
- See Also:
- LayoutManager.preferredLayoutSize(java.awt.Container)
 
 - 
layoutContainerpublic 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 the displayPolicyis 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-nullviewportBorder, 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:
- layoutContainerin interface- LayoutManager
- Parameters:
- parent- the- Containerto lay out
 
 - 
getViewportBorderBounds@Deprecated public Rectangle getViewportBorderBounds(JScrollPane scrollpane) 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 the- JScrollPane
- Returns:
- the size and position of the viewport border
 
 
- 
 
-