java.awt
Class ScrollPane

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.ScrollPane
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

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.

See Also:
Serialized Form

Nested Class Summary
protected  class ScrollPane.AccessibleAWTScrollPane
           
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static int SCROLLBARS_ALWAYS
          Constant indicating that scrollbars are always displayed in this window.
static int SCROLLBARS_AS_NEEDED
          Constant indicating that scrollbars are created as needed in this windows.
static int SCROLLBARS_NEVER
          Constant indicating that scrollbars are never displayed in this window.
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
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  void addImpl(Component component, Object constraints, int index)
          Adds the specified child component to this container.
 void addNotify()
          Notifies this object that it should create its native peer.
 void doLayout()
          Lays out this component.
protected  boolean eventTypeEnabled(int type)
          Tells whether or not an event is enabled.
 AccessibleContext getAccessibleContext()
          Gets the AccessibleContext associated with this ScrollPane.
 Adjustable getHAdjustable()
          Returns the horizontal scrollbar for this object.
 int getHScrollbarHeight()
          Returns the height of a horizontal scrollbar.
 int getScrollbarDisplayPolicy()
          Returns the current scrollbar display policy.
 Point getScrollPosition()
          Returns the current scroll position of the viewport.
 Adjustable getVAdjustable()
          Returns the vertical scrollbar for this object.
 Dimension getViewportSize()
          Returns the current viewport size.
 int getVScrollbarWidth()
          Returns the width of a vertical scrollbar.
 boolean isWheelScrollingEnabled()
          Tells whether or not wheel scrolling is enabled.
 void layout()
          Deprecated. This method is deprecated in favor of doLayout().
 String paramString()
          Returns a debug string for this object.
 void printComponents(Graphics graphics)
          Prints all of the components in this container.
 void removeNotify()
          Notifies this object that it should destroy its native peers.
 void setLayout(LayoutManager layoutManager)
          This method overrides its superclass method to ensure no layout manager is set for this container.
 void setScrollPosition(int x, int y)
          Sets the scroll position to the specified value.
 void setScrollPosition(Point scrollPosition)
          Sets the scroll position to the specified value.
 void setWheelScrollingEnabled(boolean enable)
          Enables/disables wheel scrolling.
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusDownCycle, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SCROLLBARS_AS_NEEDED

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

See Also:
Constant Field Values

SCROLLBARS_ALWAYS

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

See Also:
Constant Field Values

SCROLLBARS_NEVER

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

See Also:
Constant Field Values
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

getScrollbarDisplayPolicy

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

Returns:
The current scrollbar display policy.

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.

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.

getHScrollbarHeight

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

Returns:
The height of a horizontal scrollbar.

getVScrollbarWidth

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

Returns:
The width of a vertical scrollbar.

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.

setScrollPosition

public void setScrollPosition(Point scrollPosition)
                       throws IllegalArgumentException
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.

addNotify

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

Overrides:
addNotify in class Container
See Also:
Component.isDisplayable(), Component.removeNotify()

removeNotify

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

Overrides:
removeNotify in class Container
See Also:
Component.isDisplayable(), Component.addNotify()

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.

Overrides:
addImpl in class Container
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.

doLayout

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

Overrides:
doLayout in class Container
See Also:
Component.validate(), LayoutManager

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.

Overrides:
layout in class Container

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.

Overrides:
setLayout in class Container
Parameters:
layoutManager - Ignored
Throws:
AWTError - Always throws this error when called.

printComponents

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

Overrides:
printComponents in class Container
Parameters:
graphics - The desired graphics context for printing.

paramString

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

Overrides:
paramString in class Container
Returns:
A debug string for this object.

eventTypeEnabled

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

Parameters:
type - The event id to check.
Returns:
true if a listener for the event id exists or if the eventMask is set for the event id.
Since:
1.4
See Also:
Component.eventTypeEnabled(int)

isWheelScrollingEnabled

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

Since:
1.4

setWheelScrollingEnabled

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

Since:
1.4

getAccessibleContext

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

Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in class Component
Returns:
the associated context