java.awt

Class ScrollPane

public class ScrollPane extends Container implements Accessible

This widget provides a scrollable region that allows a single subcomponent to be viewed through a smaller window.
Nested Class Summary
protected classScrollPane.AccessibleAWTScrollPane
Field Summary
static intSCROLLBARS_ALWAYS
Constant indicating that scrollbars are always displayed in this window.
static intSCROLLBARS_AS_NEEDED
Constant indicating that scrollbars are created as needed in this windows.
static intSCROLLBARS_NEVER
Constant indicating that scrollbars are never displayed in this window.
Constructor Summary
ScrollPane()
Initializes a new instance of ScrollPane with a default scrollbar policy of SCROLLBARS_AS_NEEDED.
ScrollPane(int scrollbarDisplayPolicy)
Initializes a new instance of ScrollPane with the specified scrollbar policy.
Method Summary
protected voidaddImpl(Component component, Object constraints, int index)
Adds the specified child component to this container.
voidaddNotify()
Notifies this object that it should create its native peer.
voiddoLayout()
Lays out this component.
protected booleaneventTypeEnabled(int type)
Tells whether or not an event is enabled.
AccessibleContextgetAccessibleContext()
Gets the AccessibleContext associated with this ScrollPane.
AdjustablegetHAdjustable()
Returns the horizontal scrollbar for this object.
intgetHScrollbarHeight()
Returns the height of a horizontal scrollbar.
intgetScrollbarDisplayPolicy()
Returns the current scrollbar display policy.
PointgetScrollPosition()
Returns the current scroll position of the viewport.
AdjustablegetVAdjustable()
Returns the vertical scrollbar for this object.
DimensiongetViewportSize()
Returns the current viewport size.
intgetVScrollbarWidth()
Returns the width of a vertical scrollbar.
booleanisWheelScrollingEnabled()
Tells whether or not wheel scrolling is enabled.
voidlayout()
Lays out this component.
StringparamString()
Returns a debug string for this object.
voidprintComponents(Graphics graphics)
Prints all of the components in this container.
voidremoveNotify()
Notifies this object that it should destroy its native peers.
voidsetLayout(LayoutManager layoutManager)
This method overrides its superclass method to ensure no layout manager is set for this container.
voidsetScrollPosition(Point scrollPosition)
Sets the scroll position to the specified value.
voidsetScrollPosition(int x, int y)
Sets the scroll position to the specified value.
voidsetWheelScrollingEnabled(boolean enable)
Enables/disables wheel scrolling.

Field Detail

SCROLLBARS_ALWAYS

public static final int SCROLLBARS_ALWAYS
Constant indicating that scrollbars are always displayed in this window.

SCROLLBARS_AS_NEEDED

public static final int SCROLLBARS_AS_NEEDED
Constant indicating that scrollbars are created as needed in this windows.

SCROLLBARS_NEVER

public static final int SCROLLBARS_NEVER
Constant indicating that scrollbars are never displayed in this window.

Constructor Detail

ScrollPane

public ScrollPane()
Initializes a new instance of ScrollPane with a default scrollbar policy of SCROLLBARS_AS_NEEDED.

Throws: HeadlessException If GraphicsEnvironment.isHeadless() is true.

ScrollPane

public ScrollPane(int scrollbarDisplayPolicy)
Initializes a new instance of ScrollPane with the specified scrollbar policy.

Parameters: scrollbarDisplayPolicy When to display scrollbars, which must be one of the constants defined in this class.

Throws: HeadlessException If GraphicsEnvironment.isHeadless() is true.

Method Detail

addImpl

protected final void addImpl(Component component, Object constraints, int index)
Adds the specified child component to this container. A ScrollPane can have at most one child, so if a second one is added, then first one is removed.

Parameters: component The component to add to this container. constraints A list of layout constraints for this object. index The index at which to add the child, which is ignored in this implementation.

addNotify

public void addNotify()
Notifies this object that it should create its native peer.

doLayout

public void doLayout()
Lays out this component. This consists of resizing the sole child component to its perferred size.

eventTypeEnabled

protected boolean eventTypeEnabled(int type)
Tells whether or not an event is enabled.

Since: 1.4

getAccessibleContext

public AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with this ScrollPane. The context is created, if necessary.

Returns: the associated context

getHAdjustable

public Adjustable getHAdjustable()
Returns the horizontal scrollbar for this object. If the scrollbar display policy is set to SCROLLBARS_NEVER then this will be null.

Returns: The horizontal scrollbar for this window.

getHScrollbarHeight

public int getHScrollbarHeight()
Returns the height of a horizontal scrollbar.

Returns: The height of a horizontal scrollbar.

getScrollbarDisplayPolicy

public int getScrollbarDisplayPolicy()
Returns the current scrollbar display policy.

Returns: The current scrollbar display policy.

getScrollPosition

public Point getScrollPosition()
Returns the current scroll position of the viewport.

Returns: The current scroll position of the viewport.

Throws: NullPointerException if the scrollpane does have a child.

getVAdjustable

public Adjustable getVAdjustable()
Returns the vertical scrollbar for this object. If the scrollbar display policy is set to SCROLLBARS_NEVER then this will be null.

Returns: The horizontal scrollbar for this window.

getViewportSize

public Dimension getViewportSize()
Returns the current viewport size. The viewport is the region of this object's window where the child is actually displayed.

Returns: The viewport size.

getVScrollbarWidth

public int getVScrollbarWidth()
Returns the width of a vertical scrollbar.

Returns: The width of a vertical scrollbar.

isWheelScrollingEnabled

public boolean isWheelScrollingEnabled()
Tells whether or not wheel scrolling is enabled.

Since: 1.4

layout

public void layout()

Deprecated: This method is deprecated in favor of doLayout().

Lays out this component. This consists of resizing the sole child component to its perferred size.

paramString

public String paramString()
Returns a debug string for this object.

Returns: A debug string for this object.

printComponents

public void printComponents(Graphics graphics)
Prints all of the components in this container.

Parameters: graphics The desired graphics context for printing.

removeNotify

public void removeNotify()
Notifies this object that it should destroy its native peers.

setLayout

public final void setLayout(LayoutManager layoutManager)
This method overrides its superclass method to ensure no layout manager is set for this container. ScrollPane's do not have layout managers.

Parameters: layoutManager Ignored

Throws: AWTError Always throws this error when called.

setScrollPosition

public void setScrollPosition(Point scrollPosition)
Sets the scroll position to the specified value.

Parameters: scrollPosition The new scrollPosition.

Throws: IllegalArgumentException If the specified value is outside the legal scrolling range.

setScrollPosition

public void setScrollPosition(int x, int y)
Sets the scroll position to the specified value.

Parameters: x The new X coordinate of the scroll position. y The new Y coordinate of the scroll position.

Throws: NullPointerException if scrollpane does not have a child. IllegalArgumentException If the specified value is outside the legal scrolling range.

setWheelScrollingEnabled

public void setWheelScrollingEnabled(boolean enable)
Enables/disables wheel scrolling.

Since: 1.4