JSR-209 (Final Release)

javax.swing
Class ScrollPaneLayout

java.lang.Object
  extended byjavax.swing.ScrollPaneLayout
All Implemented Interfaces:
java.awt.LayoutManager, ScrollPaneConstants, java.io.Serializable

public class ScrollPaneLayout
extends java.lang.Object
implements java.awt.LayoutManager, ScrollPaneConstants, java.io.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 JavaBeansTM has been added to the java.beans package. Please see java.beans.XMLEncoder.

See Also:
JScrollPane, JViewport

Field Summary
protected  JViewport colHead
          The column header child.
protected  JScrollBar hsb
          The scrollpane's horizontal scrollbar child.
protected  java.awt.Component lowerLeft
          The component to display in the lower left corner.
protected  java.awt.Component lowerRight
          The component to display in the lower right corner.
protected  JViewport rowHead
          The row header child.
protected  java.awt.Component upperLeft
          The component to display in the upper left corner.
protected  java.awt.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.
 
Fields inherited from interface javax.swing.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
 
Constructor Summary
ScrollPaneLayout()
          The display policy for the horizontal scrollbar.
 
Method Summary
 void addLayoutComponent(java.lang.String s, java.awt.Component c)
          Adds the specified component to the layout.
protected  java.awt.Component addSingletonComponent(java.awt.Component oldC, java.awt.Component newC)
          Removes an existing component.
 JViewport getColumnHeader()
          Returns the JViewport object that is the column header.
 java.awt.Component getCorner(java.lang.String key)
          Returns the Component at the specified corner.
 JScrollBar getHorizontalScrollBar()
          Returns the JScrollBar object that handles horizontal scrolling.
 JViewport getRowHeader()
          Returns the JViewport object that is the row header.
 JScrollBar getVerticalScrollBar()
          Returns the JScrollBar object that handles vertical scrolling.
 JViewport getViewport()
          Returns the JViewport object that displays the scrollable contents.
 void layoutContainer(java.awt.Container parent)
          Lays out the scrollpane.
 Dimension minimumLayoutSize(java.awt.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(java.awt.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(java.awt.Component c)
          Removes the specified component from the layout.
 void syncWithScrollPane(JScrollPane sp)
          This method is invoked after the ScrollPaneLayout is set as the LayoutManager of a JScrollPane.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

viewport

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

See Also:
JScrollPane.setViewport(javax.swing.JViewport)

vsb

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

See Also:
JScrollPane.setVerticalScrollBar(javax.swing.JScrollBar)

hsb

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

See Also:
JScrollPane.setHorizontalScrollBar(javax.swing.JScrollBar)

rowHead

protected JViewport rowHead
The row header child. Default is null.

See Also:
JScrollPane.setRowHeader(javax.swing.JViewport)

colHead

protected JViewport colHead
The column header child. Default is null.

See Also:
JScrollPane.setColumnHeader(javax.swing.JViewport)

lowerLeft

protected java.awt.Component lowerLeft
The component to display in the lower left corner. Default is null.

See Also:
JScrollPane.setCorner(java.lang.String, java.awt.Component)

lowerRight

protected 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

protected 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

protected 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)
Constructor Detail

ScrollPaneLayout

public ScrollPaneLayout()
The display policy for the horizontal scrollbar. The default is JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED.

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

See Also:
JScrollPane.setHorizontalScrollBarPolicy(int)
Method Detail

syncWithScrollPane

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):
 


addSingletonComponent

protected java.awt.Component addSingletonComponent(java.awt.Component oldC,
                                                   java.awt.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 - the Component to replace
newC - the Component to add
Returns:
the newC

addLayoutComponent

public void addLayoutComponent(java.lang.String s,
                               java.awt.Component c)
Adds the specified component to the layout. The layout is identified using one of:

Specified by:
addLayoutComponent in interface java.awt.LayoutManager
Parameters:
s - the component identifier
c - the the component to be added
Throws:
java.lang.IllegalArgumentException - if s is an invalid key

removeLayoutComponent

public void removeLayoutComponent(java.awt.Component c)
Removes the specified component from the layout.

Specified by:
removeLayoutComponent in interface java.awt.LayoutManager
Parameters:
c - the component to remove

getViewport

public JViewport getViewport()
Returns the JViewport object that displays the scrollable contents.

Returns:
the JViewport object that displays the scrollable contents
See Also:
JScrollPane.getViewport()

getHorizontalScrollBar

public JScrollBar getHorizontalScrollBar()
Returns the JScrollBar object that handles horizontal scrolling.

Returns:
the JScrollBar object that handles horizontal scrolling
See Also:
JScrollPane.getHorizontalScrollBar()

getVerticalScrollBar

public JScrollBar getVerticalScrollBar()
Returns the JScrollBar object that handles vertical scrolling.

Returns:
the JScrollBar object that handles vertical scrolling
See Also:
JScrollPane.getVerticalScrollBar()

getRowHeader

public JViewport getRowHeader()
Returns the JViewport object that is the row header.

Returns:
the JViewport object that is the row header
See Also:
JScrollPane.getRowHeader()

getColumnHeader

public JViewport getColumnHeader()
Returns the JViewport object that is the column header.

Returns:
the JViewport object that is the column header
See Also:
JScrollPane.getColumnHeader()

getCorner

public java.awt.Component getCorner(java.lang.String key)
Returns the Component at the specified corner.

Parameters:
key - the String specifying the corner
Returns:
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(java.lang.String)

preferredLayoutSize

public Dimension preferredLayoutSize(java.awt.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.

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 interface java.awt.LayoutManager
Parameters:
parent - the Container that will be laid out
Returns:
a Dimension object specifying the preferred size of the viewport and any scrollbars
See Also:
ViewportLayout, LayoutManager

minimumLayoutSize

public Dimension minimumLayoutSize(java.awt.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.

Specified by:
minimumLayoutSize in interface java.awt.LayoutManager
Parameters:
parent - the Container that will be laid out
Returns:
a Dimension object specifying the minimum size

layoutContainer

public void layoutContainer(java.awt.Container parent)
Lays out the scrollpane. The positioning of components depends on the following constraints:

Specified by:
layoutContainer in interface java.awt.LayoutManager
Parameters:
parent - the Container to lay out

JSR-209 (Final Release)

Java and Java 2D are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
Copyright 1993 - 2006 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, U.S.A. All Rights Reserved.
Use of this specification is subject to this license.