java.awt
Class ScrollPane

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.ScrollPane
All Implemented Interfaces:
Accessible, java.awt.image.ImageObserver, MenuContainer, Serializable

public class ScrollPane
extends Container
implements Accessible

Unsafe:

See Also:
Serialized Form

Field Summary
private static String base
           
private static boolean defaultWheelScroll
           
private  ScrollPaneAdjustable hAdjustable
          An adjustable horizontal scrollbar.
private static int nameCounter
           
private  int scrollbarDisplayPolicy
          There are 3 ways in which a scroll bar can be displayed.
static int SCROLLBARS_ALWAYS
          Enabled: Specifies that horizontal/vertical scrollbars should always be shown regardless of the respective sizes of the scrollpane and child.
static int SCROLLBARS_AS_NEEDED
          Enabled: Specifies that horizontal/vertical scrollbar should be shown only when the size of the child exceeds the size of the scrollpane in the horizontal/vertical dimension.
static int SCROLLBARS_NEVER
          Enabled: Specifies that horizontal/vertical scrollbars should never be shown regardless of the respective sizes of the scrollpane and child.
private static long serialVersionUID
           
private  ScrollPaneAdjustable vAdjustable
          An adjustable vertical scrollbar.
private  boolean wheelScrollingEnabled
          Indicates whether or not scrolling should take place when a MouseWheelEvent is received.
 
Fields inherited from class java.awt.Container
component, containerListener, descendantsCount, INCLUDE_SELF, layoutMgr, listeningBoundsChildren, listeningChildren, ncomponents, SEARCH_HEAVYWEIGHTS
 
Fields inherited from class java.awt.Component
accessibleContext, actionListenerK, adjustmentListenerK, appContext, background, BOTTOM_ALIGNMENT, bufferStrategy, CENTER_ALIGNMENT, componentListener, componentListenerK, componentOrientation, containerListenerK, cursor, dropTarget, enabled, eventMask, focusListener, focusListenerK, focusTraversalKeys, font, foreground, graphicsConfig, height, hierarchyBoundsListener, hierarchyBoundsListenerK, hierarchyListener, hierarchyListenerK, ignoreRepaint, incRate, inputMethodListener, inputMethodListenerK, isInc, isPacked, itemListenerK, keyListener, keyListenerK, LEFT_ALIGNMENT, locale, LOCK, metrics, minSize, mouseListener, mouseListenerK, mouseMotionListener, mouseMotionListenerK, mouseWheelListener, mouseWheelListenerK, newEventsOnly, ownedWindowK, parent, peer, peerFont, popups, prefSize, RIGHT_ALIGNMENT, textListenerK, TOP_ALIGNMENT, valid, visible, width, windowClosingException, windowFocusListenerK, windowListenerK, windowStateListenerK, x, y
 
Constructor Summary
ScrollPane()
          Suppressed: Create a new scrollpane container with a scrollbar display policy of "as needed".
ScrollPane(int scrollbarDisplayPolicy)
          Suppressed: Create a new scrollpane container.
 
Method Summary
protected  void addImpl(Component comp, Object constraints, int index)
          Adds the specified component to this scroll pane container.
 void addNotify()
          Suppressed: Creates the scroll pane's peer.
(package private)  void autoProcessMouseWheel(MouseWheelEvent e)
           
(package private)  Dimension calculateChildSize()
          Determine the size to allocate the child component.
(package private)  String constructComponentName()
          Construct a name for this component.
 void doLayout()
          Suppressed: Lays out this container by resizing its child to its preferred size.
protected  boolean eventTypeEnabled(int type)
          If wheel scrolling is enabled, we return true for MouseWheelEvents
 AccessibleContext getAccessibleContext()
          Suppressed: Gets the AccessibleContext associated with this ScrollPane.
 Adjustable getHAdjustable()
          Suppressed: Returns the ScrollPaneAdjustable object which represents the state of the horizontal scrollbar.
 int getHScrollbarHeight()
          Suppressed: Returns the height that would be occupied by a horizontal scrollbar, which is independent of whether it is currently displayed by the scroll pane or not.
 int getScrollbarDisplayPolicy()
          Suppressed: Returns the display policy for the scrollbars.
 Point getScrollPosition()
          Suppressed: Returns the current x,y position within the child which is displayed at the 0,0 location of the scrolled panel's view port.
 Adjustable getVAdjustable()
          Suppressed: Returns the ScrollPaneAdjustable object which represents the state of the vertical scrollbar.
 Dimension getViewportSize()
          Suppressed: Returns the current size of the scroll pane's view port.
 int getVScrollbarWidth()
          Suppressed: Returns the width that would be occupied by a vertical scrollbar, which is independent of whether it is currently displayed by the scroll pane or not.
private static void initIDs()
          Initialize JNI field and method IDs
 boolean isWheelScrollingEnabled()
          Suppressed: Indicates whether or not scrolling will take place in response to the mouse wheel.
 void layout()
          Suppressed: @deprecated As of JDK version 1.1, replaced by doLayout().
 String paramString()
          Suppressed: Returns a string representing the state of this ScrollPane.
 void printComponents(Graphics g)
          Suppressed: Prints the component in this scroll pane.
protected  void processMouseWheelEvent(MouseWheelEvent e)
          Process mouse wheel events that are delivered to this ScrollPane by scrolling an appropriate amount.
private  void readObject(ObjectInputStream s)
          Reads default serializable fields to stream.
 void setLayout(LayoutManager mgr)
          Suppressed: Sets the layout manager for this container.
 void setScrollPosition(int x, int y)
          Suppressed: Scrolls to the specified position within the child component.
 void setScrollPosition(Point p)
          Suppressed: Scrolls to the specified position within the child component.
 void setWheelScrollingEnabled(boolean handleWheel)
          Suppressed: Enables/disables scrolling in response to movement of the mouse wheel.
private  void writeObject(ObjectOutputStream s)
          Writes default serializable fields to stream.
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, adjustDecendantsOnParent, adjustDescendants, adjustListeningChildren, applyComponentOrientation, areFocusTraversalKeysSet, checkGD, clearCurrentFocusCycleRootOnHide, clearMostRecentFocusOwnerOnHide, containsFocus, countComponents, countHierarchyMembers, createChildHierarchyEvents, createHierarchyEvents, deliverEvent, dispatchEventImpl, dispatchEventToSelf, eventEnabled, findComponentAt, findComponentAt, findComponentAt, get, getAccessibleAt, getAccessibleChild, getAccessibleChildrenCount, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents_NoClientCode, getComponents, getContainerListeners, getDropTargetEventTarget, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMouseEventTarget, getPreferredSize, initializeFocusTraversalKeys, insets, invalidate, invalidateTree, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, iterate, lightweightPaint, lightweightPrint, list, list, locate, minimumSize, nextFocusHelper, numListening, paint, paintComponents, paintHeavyweightComponents, postProcessKeyEvent, postsOldMouseEvents, preferredSize, preProcessKeyEvent, print, printHeavyweightComponents, processContainerEvent, processEvent, proxyEnableEvents, remove, remove, removeAll, removeContainerListener, removeNotify, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, setZOrder, size, transferFocusBackward, transferFocusDownCycle, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, adjustListeningChildrenOnParent, areInputMethodsEnabled, autoTransferFocus, bounds, checkImage, checkImage, checkWindowClosingException, coalesceEvents, contains, contains, createBufferStrategy, createBufferStrategy, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, dispatchMouseWheelToAncestor, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleIndexInParent, getAccessibleStateSet, getBackBuffer, getBackground, getBounds, getBounds, getBufferStrategy, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys_NoIDCheck, getFocusTraversalKeysEnabled, getFont_NoClientCode, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen_NoTreeLock, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getNativeContainer, getParent_NoClientCode, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getToolkitImpl, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isEnabledImpl, isFocusable, isFocusOwner, isFocusTraversable, isFocusTraversableOverridden, isFontSet, isForegroundSet, isLightweight, isOpaque, isRecursivelyVisible, 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, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusHelper, requestFocusInWindow, requestFocusInWindow, resetGC, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys_NoIDCheck, setFocusTraversalKeysEnabled, setForeground, setGCFromPeer, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, toString, transferFocus, transferFocus, transferFocusUpCycle, updateCursorImmediately
 
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
Enabled: Specifies that horizontal/vertical scrollbar should be shown only when the size of the child exceeds the size of the scrollpane in the horizontal/vertical dimension.


SCROLLBARS_ALWAYS

public static final int SCROLLBARS_ALWAYS
Enabled: Specifies that horizontal/vertical scrollbars should always be shown regardless of the respective sizes of the scrollpane and child.


SCROLLBARS_NEVER

public static final int SCROLLBARS_NEVER
Enabled: Specifies that horizontal/vertical scrollbars should never be shown regardless of the respective sizes of the scrollpane and child.


scrollbarDisplayPolicy

private int scrollbarDisplayPolicy
There are 3 ways in which a scroll bar can be displayed. This integer will represent one of these 3 displays - (SCROLLBARS_ALWAYS, SCROLLBARS_AS_NEEDED, SCROLLBARS_NEVER)

See Also:
getScrollbarDisplayPolicy()

vAdjustable

private ScrollPaneAdjustable vAdjustable
An adjustable vertical scrollbar. It is important to note that you must NOT call 3 Adjustable methods, namely: setMinimum(), setMaximum(), setVisibleAmount().

See Also:
getVAdjustable()

hAdjustable

private ScrollPaneAdjustable hAdjustable
An adjustable horizontal scrollbar. It is important to note that you must NOT call 3 Adjustable methods, namely: setMinimum(), setMaximum(), setVisibleAmount().

See Also:
getHAdjustable()

base

private static final String base

nameCounter

private static int nameCounter

defaultWheelScroll

private static final boolean defaultWheelScroll

wheelScrollingEnabled

private boolean wheelScrollingEnabled
Indicates whether or not scrolling should take place when a MouseWheelEvent is received.

Since:
1.4

serialVersionUID

private static final long serialVersionUID
Constructor Detail

ScrollPane

public ScrollPane()
           throws HeadlessException
Suppressed: Create a new scrollpane container with a scrollbar display policy of "as needed".

Throws:
HeadlessException - if GraphicsEnvironment.isHeadless() returns true
See Also:
java.awt.GraphicsEnvironment#isHeadless

ScrollPane

public ScrollPane(int scrollbarDisplayPolicy)
           throws HeadlessException
Suppressed: Create a new scrollpane container.

Parameters:
scrollbarDisplayPolicy - policy for when scrollbars should be shown
Throws:
IllegalArgumentException - if the specified scrollbar display policy is invalid
HeadlessException - if GraphicsEnvironment.isHeadless() returns true
See Also:
java.awt.GraphicsEnvironment#isHeadless
Method Detail

initIDs

private static void initIDs()
Initialize JNI field and method IDs


constructComponentName

String constructComponentName()
Construct a name for this component. Called by getName() when the name is null.

Overrides:
constructComponentName in class Component

addImpl

protected final void addImpl(Component comp,
                             Object constraints,
                             int index)
Adds the specified component to this scroll pane container. If the scroll pane has an existing child component, that component is removed and the new one is added.

Overrides:
addImpl in class Container
Parameters:
comp - the component to be added
constraints - not applicable
index - position of child component (must be <= 0)
See Also:
Container.add(Component), Container.add(Component, int), Container.add(Component, java.lang.Object), LayoutManager, LayoutManager2

getScrollbarDisplayPolicy

public int getScrollbarDisplayPolicy()
Suppressed: Returns the display policy for the scrollbars.

Returns:
the display policy for the scrollbars

getViewportSize

public Dimension getViewportSize()
Suppressed: Returns the current size of the scroll pane's view port.

Returns:
the size of the view port in pixels

getHScrollbarHeight

public int getHScrollbarHeight()
Suppressed: Returns the height that would be occupied by a horizontal scrollbar, which is independent of whether it is currently displayed by the scroll pane or not.

Returns:
the height of a horizontal scrollbar in pixels

getVScrollbarWidth

public int getVScrollbarWidth()
Suppressed: Returns the width that would be occupied by a vertical scrollbar, which is independent of whether it is currently displayed by the scroll pane or not.

Returns:
the width of a vertical scrollbar in pixels

getVAdjustable

public Adjustable getVAdjustable()
Suppressed: Returns the ScrollPaneAdjustable object which represents the state of the vertical scrollbar. The declared return type of this method is Adjustable to maintain backward compatibility.

See Also:
java.awt.ScrollPaneAdjustable

getHAdjustable

public Adjustable getHAdjustable()
Suppressed: Returns the ScrollPaneAdjustable object which represents the state of the horizontal scrollbar. The declared return type of this method is Adjustable to maintain backward compatibility.

See Also:
java.awt.ScrollPaneAdjustable

setScrollPosition

public void setScrollPosition(int x,
                              int y)
Suppressed: Scrolls to the specified position within the child component. A call to this method is only valid if the scroll pane contains a child. Specifying a position outside of the legal scrolling bounds of the child will scroll to the closest legal position. Legal bounds are defined to be the rectangle: x = 0, y = 0, width = (child width - view port width), height = (child height - view port height). This is a convenience method which interfaces with the Adjustable objects which represent the state of the scrollbars.

Parameters:
x - the x position to scroll to
y - the y position to scroll to
Throws:
NullPointerException - if the scrollpane does not contain a child

setScrollPosition

public void setScrollPosition(Point p)
Suppressed: Scrolls to the specified position within the child component. A call to this method is only valid if the scroll pane contains a child and the specified position is within legal scrolling bounds of the child. Specifying a position outside of the legal scrolling bounds of the child will scroll to the closest legal position. Legal bounds are defined to be the rectangle: x = 0, y = 0, width = (child width - view port width), height = (child height - view port height). This is a convenience method which interfaces with the Adjustable objects which represent the state of the scrollbars.

Parameters:
p - the Point representing the position to scroll to

getScrollPosition

public Point getScrollPosition()
Suppressed: Returns the current x,y position within the child which is displayed at the 0,0 location of the scrolled panel's view port. This is a convenience method which interfaces with the adjustable objects which represent the state of the scrollbars.

Returns:
the coordinate position for the current scroll position
Throws:
NullPointerException - if the scrollpane does not contain a child

setLayout

public final void setLayout(LayoutManager mgr)
Suppressed: Sets the layout manager for this container. This method is overridden to prevent the layout mgr from being set.

Overrides:
setLayout in class Container
Parameters:
mgr - the specified layout manager
See Also:
Container.doLayout(), Container.getLayout()

doLayout

public void doLayout()
Suppressed: Lays out this container by resizing its child to its preferred size. If the new preferred size of the child causes the current scroll position to be invalid, the scroll position is set to the closest valid position.

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

calculateChildSize

Dimension calculateChildSize()
Determine the size to allocate the child component. If the viewport area is bigger than the childs preferred size then the child is allocated enough to fill the viewport, otherwise the child is given it's preferred size.


layout

public void layout()
Suppressed: @deprecated As of JDK version 1.1, replaced by doLayout().

Overrides:
layout in class Container

printComponents

public void printComponents(Graphics g)
Suppressed: Prints the component in this scroll pane.

Overrides:
printComponents in class Container
Parameters:
g - the specified Graphics window
See Also:
Component.print(java.awt.Graphics), Component.printAll(java.awt.Graphics)

addNotify

public void addNotify()
Suppressed: Creates the scroll pane's peer.

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

paramString

public String paramString()
Suppressed: Returns a string representing the state of this ScrollPane. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null.

Overrides:
paramString in class Container
Returns:
the parameter string of this scroll pane

autoProcessMouseWheel

void autoProcessMouseWheel(MouseWheelEvent e)
Overrides:
autoProcessMouseWheel in class Component

processMouseWheelEvent

protected void processMouseWheelEvent(MouseWheelEvent e)
Process mouse wheel events that are delivered to this ScrollPane by scrolling an appropriate amount.

Note that if the event parameter is null the behavior is unspecified and may result in an exception.

Overrides:
processMouseWheelEvent in class Component
Parameters:
e - the mouse wheel event
Since:
1.4
See Also:
java.awt.event.MouseWheelEvent, java.awt.event.MouseWheelListener, Component.addMouseWheelListener(java.awt.event.MouseWheelListener), Component.enableEvents(long)

eventTypeEnabled

protected boolean eventTypeEnabled(int type)
If wheel scrolling is enabled, we return true for MouseWheelEvents

Overrides:
eventTypeEnabled in class Component
Since:
1.4

setWheelScrollingEnabled

public void setWheelScrollingEnabled(boolean handleWheel)
Suppressed: Enables/disables scrolling in response to movement of the mouse wheel. Wheel scrolling is enabled by default.

Parameters:
handleWheel - true if scrolling should be done automatically for a MouseWheelEvent, false otherwise.
Since:
1.4
See Also:
isWheelScrollingEnabled(), java.awt.event.MouseWheelEvent, java.awt.event.MouseWheelListener

isWheelScrollingEnabled

public boolean isWheelScrollingEnabled()
Suppressed: Indicates whether or not scrolling will take place in response to the mouse wheel. Wheel scrolling is enabled by default.

Since:
1.4
See Also:
setWheelScrollingEnabled(boolean)

writeObject

private void writeObject(ObjectOutputStream s)
                  throws IOException
Writes default serializable fields to stream.

Parameters:
s - the ObjectOutputStream to write
IOException
See Also:
AWTEventMulticaster.save(java.io.ObjectOutputStream, java.lang.String, java.util.EventListener), Component.containerListenerK, Container.readObject(java.io.ObjectInputStream)

readObject

private void readObject(ObjectInputStream s)
                 throws ClassNotFoundException,
                        IOException,
                        HeadlessException
Reads default serializable fields to stream.

Parameters:
s - the ObjectInputStream to read
ClassNotFoundException
IOException
HeadlessException
See Also:
java.awt.GraphicsEnvironment#isHeadless

getAccessibleContext

public AccessibleContext getAccessibleContext()
Suppressed: Gets the AccessibleContext associated with this ScrollPane. For scroll panes, the AccessibleContext takes the form of an AccessibleAWTScrollPane. A new AccessibleAWTScrollPane instance is created if necessary.

Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in class Component
Returns:
an AccessibleAWTScrollPane that serves as the AccessibleContext of this ScrollPane


comments?