java.awt

Class ScrollPane

Implemented Interfaces:
Accessible, ImageObserver, MenuContainer, Serializable

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.
Point
getScrollPosition()
Returns the current scroll position of the viewport.
int
getScrollbarDisplayPolicy()
Returns the current scrollbar display policy.
Adjustable
getVAdjustable()
Returns the vertical scrollbar for this object.
int
getVScrollbarWidth()
Returns the width of a vertical scrollbar.
Dimension
getViewportSize()
Returns the current viewport size.
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, addImpl, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, extends EventListener> T[] getListeners, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponentZOrder, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusDownCycle, update, validate, validateTree

Methods inherited from class java.awt.Component

action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, extends EventListener> T[] getListeners, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFocusable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFocusable, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

SCROLLBARS_ALWAYS

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

SCROLLBARS_AS_NEEDED

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

SCROLLBARS_NEVER

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

Constructor Details

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 Details

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 interface 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.

addNotify

public void addNotify()
Notifies this object that it should create its native peer.
Overrides:
addNotify in interface Container

doLayout

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

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.
Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in interface Component
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.

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.

getScrollbarDisplayPolicy

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

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.

getVScrollbarWidth

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

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.

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.
Overrides:
layout in interface Container

paramString

public String paramString()
Returns a debug string for this object.
Overrides:
paramString in interface Container
Returns:
A debug string for this object.

printComponents

public void printComponents(Graphics graphics)
Prints all of the components in this container.
Overrides:
printComponents in interface Container
Parameters:
graphics - The desired graphics context for printing.

removeNotify

public void removeNotify()
Notifies this object that it should destroy its native peers.
Overrides:
removeNotify in interface 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 interface Container
Parameters:
layoutManager - Ignored

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.

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.

setWheelScrollingEnabled

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

ScrollPane.java -- Scrolling window Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.