This documentation differs from the official API.
Jadeite adds
extra features to the API including:
variable font sizes,
constructions examples,
placeholders for classes and methods, and auto-generated “See Also” links.
Additionally it
is missing some items found in standard Javadoc documentation, including:
generics type information,
“Deprecated” tags and comments,
“See Also” links,
along with other minor differences.
Please send any questions or feedback to
bam@cs.cmu.edu.
java.awt
class ScrollPane
- All Implemented Interfaces:
- MenuContainer, ImageObserver, Serializable, Accessible
-
Most common way to construct:
-
ScrollPane pane = new ScrollPane();
Based on 38 examples
public class ScrollPane
extends Container
implements Accessible
A container class which implements automatic horizontal and/or
vertical scrolling for a single child component. The display
policy for the scrollbars can be set to:
- as needed: scrollbars created and shown only when needed by scrollpane
- always: scrollbars created and always shown by the scrollpane
- never: scrollbars never created or shown by the scrollpane
The state of the horizontal and vertical scrollbars is represented
by two ScrollPaneAdjustable
objects (one for each
dimension) which implement the Adjustable
interface.
The API provides methods to access those objects such that the
attributes on the Adjustable object (such as unitIncrement, value,
etc.) can be manipulated.
Certain adjustable properties (minimum, maximum, blockIncrement,
and visibleAmount) are set internally by the scrollpane in accordance
with the geometry of the scrollpane and its child and these should
not be set by programs using the scrollpane.
If the scrollbar display policy is defined as "never", then the
scrollpane can still be programmatically scrolled using the
setScrollPosition() method and the scrollpane will move and clip
the child's contents appropriately. This policy is useful if the
program needs to create and manage its own adjustable controls.
The placement of the scrollbars is controlled by platform-specific
properties set by the user outside of the program.
The initial size of this container is set to 100x100, but can
be reset using setSize().
Scrolling with the wheel on a wheel-equipped mouse is enabled by default.
This can be disabled using setWheelScrollingEnabled
.
Wheel scrolling can be customized by setting the block and
unit increment of the horizontal and vertical Adjustables.
For information on how mouse wheel events are dispatched, see
the class description for {@link MouseWheelEvent}.
Insets are used to define any space used by scrollbars and any
borders created by the scroll pane. getInsets() can be used
to get the current value for the insets. If the value of
scrollbarsAlwaysVisible is false, then the value of the insets
will change dynamically depending on whether the scrollbars are
currently visible or not.
Nested Class Summary |
protected class |
This class implements accessibility support for the
ScrollPane class. |
Field Summary |
static int |
SCROLLBARS_ALWAYS
Specifies that horizontal/vertical scrollbars should always be
shown regardless of the respective sizes of the scrollpane and child. |
static int |
SCROLLBARS_AS_NEEDED
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
Specifies that horizontal/vertical scrollbars should never be shown
regardless of the respective sizes of the scrollpane and child. |
Constructor Summary |
Create a new scrollpane container with a scrollbar display
policy of "as needed".
|
Create a new scrollpane container.
|
Method Summary |
protected void |
Adds the specified component to this scroll pane container.
|
void |
Creates the scroll pane's peer.
|
void |
Lays out this container by resizing its child to its preferred size.
|
protected boolean |
If wheel scrolling is enabled, we return true for MouseWheelEvents
|
AccessibleContext |
Gets the AccessibleContext associated with this ScrollPane.
|
Adjustable |
Returns the ScrollPaneAdjustable object which
represents the state of the horizontal scrollbar.
|
int |
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 |
Returns the display policy for the scrollbars.
|
Point |
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 |
Returns the ScrollPaneAdjustable object which
represents the state of the vertical scrollbar.
|
Dimension |
Returns the current size of the scroll pane's view port.
|
int |
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.
|
boolean |
Indicates whether or not scrolling will take place in response to
the mouse wheel.
|
void |
|
String |
Returns a string representing the state of this
ScrollPane .
|
void |
Prints the component in this scroll pane.
|
protected void |
Process mouse wheel events that are delivered to this
ScrollPane by scrolling an appropriate amount.
|
void |
Sets the layout manager for this container.
|
void |
Scrolls to the specified position within the child component.
|
void |
Scrolls to the specified position within the child component.
|
void |
Enables/disables scrolling in response to movement of the mouse wheel.
|
Methods inherited from class java.awt.Container |
add, add, add, add, add, addContainerListener, addImpl, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, 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, 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, transferFocusBackward, 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, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, 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, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, 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, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, 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, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, 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, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SCROLLBARS_ALWAYS
public static final int SCROLLBARS_ALWAYS
-
Specifies that horizontal/vertical scrollbars should always be
shown regardless of the respective sizes of the scrollpane and child.
SCROLLBARS_AS_NEEDED
public static final int SCROLLBARS_AS_NEEDED
-
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_NEVER
public static final int SCROLLBARS_NEVER
-
Specifies that horizontal/vertical scrollbars should never be shown
regardless of the respective sizes of the scrollpane and child.
ScrollPane
public ScrollPane()
throws HeadlessException
-
Create a new scrollpane container with a scrollbar display
policy of "as needed".
- Throws:
HeadlessException
- if GraphicsEnvironment.isHeadless()
returns true
ScrollPane
public ScrollPane(int scrollbarDisplayPolicy)
throws HeadlessException
-
Create a new scrollpane container.
- Parameters:
scrollbarDisplayPolicy
- policy for when scrollbars should be shown
- Throws:
HeadlessException
- if GraphicsEnvironment.isHeadless()
returns true
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)
addNotify
public void addNotify()
-
Creates the scroll pane's peer.
- Overrides:
addNotify
in class Container
doLayout
public void doLayout()
-
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
eventTypeEnabled
protected boolean eventTypeEnabled(int type)
-
If wheel scrolling is enabled, we return true for MouseWheelEvents
- Overrides:
eventTypeEnabled
in class Component
- Parameters:
type
getAccessibleContext
public AccessibleContext getAccessibleContext()
-
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.
- Overrides:
getAccessibleContext
in class Component
- Returns:
- an AccessibleAWTScrollPane that serves as the
AccessibleContext of this ScrollPane
getHAdjustable
public Adjustable getHAdjustable()
-
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.
getHScrollbarHeight
public int getHScrollbarHeight()
-
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
getScrollbarDisplayPolicy
public int getScrollbarDisplayPolicy()
-
Returns the display policy for the scrollbars.
- Returns:
- the display policy for the scrollbars
getScrollPosition
public Point getScrollPosition()
-
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
getVAdjustable
public Adjustable getVAdjustable()
-
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.
getViewportSize
public Dimension getViewportSize()
-
Returns the current size of the scroll pane's view port.
- Returns:
- the size of the view port in pixels
getVScrollbarWidth
public int getVScrollbarWidth()
-
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
isWheelScrollingEnabled
public boolean isWheelScrollingEnabled()
-
Indicates whether or not scrolling will take place in response to
the mouse wheel. Wheel scrolling is enabled by default.
layout
public void layout()
-
- Overrides:
layout
in class Container
paramString
public String paramString()
-
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
printComponents
public void printComponents(Graphics g)
-
Prints the component in this scroll pane.
- Overrides:
printComponents
in class Container
- Parameters:
g
- the specified Graphics window
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
setLayout
public final void setLayout(LayoutManager mgr)
-
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
setScrollPosition
public void setScrollPosition(int x,
int y)
-
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
setScrollPosition
public void setScrollPosition(Point p)
-
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
setWheelScrollingEnabled
public void setWheelScrollingEnabled(boolean handleWheel)
-
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.
This documentation differs from the official API.
Jadeite adds
extra features to the API including:
variable font sizes,
constructions examples,
placeholders for classes and methods, and auto-generated “See Also” links.
Additionally it
is missing some items found in standard Javadoc documentation, including:
generics type information,
“Deprecated” tags and comments,
“See Also” links,
along with other minor differences.
Please send any questions or feedback to
bam@cs.cmu.edu.
This page displays the
Jadeite version of the documention, which is derived from the offical documentation that contains this copyright notice:
The official Sun™ documentation can be found here at
http://java.sun.com/javase/6/docs/api/.