Class ScrollPane
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- java.awt.ScrollPane
-
- All Implemented Interfaces:
- java.awt.image.ImageObserver, MenuContainer, java.io.Serializable, javax.accessibility.Accessible
public class ScrollPane extends Container implements javax.accessibility.AccessibleA 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 theAdjustable
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 forMouseWheelEvent
.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.
- See Also:
- Serialized Form
-
-
Nested Classes Modifier and Type Class and Description AccessibleAWTComponent Inner class of Component used to provide default support for accessibility.BaselineResizeBehavior Enumeration of the common ways the baseline of a component can change as the size changes.BltBufferStrategy Inner class for blitting offscreen surfaces to a component.FlipBufferStrategy Inner class for flipping buffers on a component.AccessibleAWTContainer Inner class of Container used to provide default support for accessibility.AccessibleAWTScrollPane This class implements accessibility support for theScrollPane
class.
-
Fields Modifier and Type Field and Description ABORT This flag in the infoflags argument to imageUpdate indicates that an image which was being tracked asynchronously was aborted before production was complete.ALLBITS This flag in the infoflags argument to imageUpdate indicates that a static image which was previously drawn is now complete and can be drawn again in its final form.BOTTOM_ALIGNMENT Ease-of-use constant forgetAlignmentY
.CENTER_ALIGNMENT Ease-of-use constant forgetAlignmentY
andgetAlignmentX
.ERROR This flag in the infoflags argument to imageUpdate indicates that an image which was being tracked asynchronously has encountered an error.FRAMEBITS This flag in the infoflags argument to imageUpdate indicates that another complete frame of a multi-frame image which was previously drawn is now available to be drawn again.HEIGHT This flag in the infoflags argument to imageUpdate indicates that the height of the base image is now available and can be taken from the height argument to the imageUpdate callback method.LEFT_ALIGNMENT Ease-of-use constant forgetAlignmentX
.PROPERTIES This flag in the infoflags argument to imageUpdate indicates that the properties of the image are now available.RIGHT_ALIGNMENT Ease-of-use constant forgetAlignmentX
.SCROLLBARS_ALWAYS Specifies that horizontal/vertical scrollbars should always be shown regardless of the respective sizes of the scrollpane and child.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 Specifies that horizontal/vertical scrollbars should never be shown regardless of the respective sizes of the scrollpane and child.SOMEBITS This flag in the infoflags argument to imageUpdate indicates that more pixels needed for drawing a scaled variation of the image are available.TOP_ALIGNMENT Ease-of-use constant forgetAlignmentY()
.WIDTH This flag in the infoflags argument to imageUpdate indicates that the width of the base image is now available and can be taken from the width argument to the imageUpdate callback method.
-
Constructors Constructor and Description ScrollPane Create a new scrollpane container with a scrollbar display policy of "as needed".ScrollPane Create a new scrollpane container.
-
-
Basic Attribute Methods Modifier and Type Method and Description applyComponentOrientation Sets theComponentOrientation
property of this container and all components contained within it.disable Deprecated. As of JDK version 1.1, replaced bysetEnabled(boolean)
.enable Deprecated. As of JDK version 1.1, replaced bysetEnabled(boolean)
.enable Deprecated. As of JDK version 1.1, replaced bysetEnabled(boolean)
.enableInputMethods Enables or disables input method support for this component.getAccessibleContext Gets the AccessibleContext associated with this ScrollPane.getBackground Gets the background color of this component.getColorModel Gets the instance ofColorModel
used to display the component on the output device.getComponentOrientation Retrieves the language-sensitive orientation that is to be used to order the elements or text within this component.getCursor Gets the cursor set in the component.getFont Gets the font of this component.getForeground Gets the foreground color of this component.getLocale Gets the locale of this component.getName Gets the name of the component.getParent Gets the parent of this component.hide Deprecated. As of JDK version 1.1, replaced bysetVisible(boolean)
.isBackgroundSet Returns whether the background color has been explicitly set for this Component.isCursorSet Returns whether the cursor has been explicitly set for this Component.isDisplayable Determines whether this component is displayable.isDoubleBuffered Returns true if this component is painted to an offscreen image ("buffer") that's copied to the screen later.isEnabled Determines whether this component is enabled.isFontSet Returns whether the font has been explicitly set for this Component.isForegroundSet Returns whether the foreground color has been explicitly set for this Component.isLightweight A lightweight component doesn't have a native toolkit peer.isOpaque Returns true if this component is completely opaque, returns false by default.isShowing Determines whether this component is showing on screen.isVisible Determines whether this component should be visible when its parent is visible.setBackground Sets the background color of this component.setComponentOrientation Sets the language-sensitive orientation that is to be used to order the elements or text within this component.setCursor Sets the cursor image to the specified cursor.setEnabled Enables or disables this component, depending on the value of the parameterb
.setFont Sets the font of this container.setForeground Sets the foreground color of this component.setLocale Sets the locale of this component.setName Sets the name of the component to the specified string.setVisible Shows or hides this component depending on the value of parameterb
.show Deprecated. As of JDK version 1.1, replaced bysetVisible(boolean)
.show Deprecated. As of JDK version 1.1, replaced bysetVisible(boolean)
. -
Event Support Methods Modifier and Type Method and Description action Deprecated. As of JDK version 1.1, should register this component as ActionListener on component which fires action events.coalesceEvents Potentially coalesce an event being posted with an existing event.deliverEvent Deprecated. As of JDK version 1.1, replaced bydispatchEvent(AWTEvent e)
disableEvents Disables the events defined by the specified event mask parameter from being delivered to this component.dispatchEvent Dispatches an event to this component or one of its sub components.enableEvents Enables the events defined by the specified event mask parameter to be delivered to this component.firePropertyChange Support for reporting bound property changes for boolean properties.firePropertyChange Reports a bound property change.firePropertyChange Reports a bound property change.firePropertyChange Reports a bound property change.firePropertyChange Reports a bound property change.firePropertyChange Support for reporting bound property changes for integer properties.firePropertyChange Reports a bound property change.firePropertyChange Support for reporting bound property changes for Object properties.firePropertyChange Reports a bound property change.getListeners Returns an array of all the objects currently registered asFooListener
s upon thisContainer
.handleEvent Deprecated. As of JDK version 1.1 replaced by processEvent(AWTEvent).keyDown Deprecated. As of JDK version 1.1, replaced by processKeyEvent(KeyEvent).keyUp Deprecated. As of JDK version 1.1, replaced by processKeyEvent(KeyEvent).mouseDown Deprecated. As of JDK version 1.1, replaced by processMouseEvent(MouseEvent).mouseDrag Deprecated. As of JDK version 1.1, replaced by processMouseMotionEvent(MouseEvent).mouseEnter Deprecated. As of JDK version 1.1, replaced by processMouseEvent(MouseEvent).mouseExit Deprecated. As of JDK version 1.1, replaced by processMouseEvent(MouseEvent).mouseMove Deprecated. As of JDK version 1.1, replaced by processMouseMotionEvent(MouseEvent).mouseUp Deprecated. As of JDK version 1.1, replaced by processMouseEvent(MouseEvent).postEvent Deprecated. As of JDK version 1.1, replaced by dispatchEvent(AWTEvent).processComponentEvent Processes component events occurring on this component by dispatching them to any registeredComponentListener
objects.processContainerEvent Processes container events occurring on this container by dispatching them to any registered ContainerListener objects.processEvent Processes events on this container.processFocusEvent Processes focus events occurring on this component by dispatching them to any registeredFocusListener
objects.processHierarchyBoundsEvent Processes hierarchy bounds events occurring on this component by dispatching them to any registeredHierarchyBoundsListener
objects.processHierarchyEvent Processes hierarchy events occurring on this component by dispatching them to any registeredHierarchyListener
objects.processInputMethodEvent Processes input method events occurring on this component by dispatching them to any registeredInputMethodListener
objects.processKeyEvent Processes key events occurring on this component by dispatching them to any registeredKeyListener
objects.processMouseEvent Processes mouse events occurring on this component by dispatching them to any registeredMouseListener
objects.processMouseMotionEvent Processes mouse motion events occurring on this component by dispatching them to any registeredMouseMotionListener
objects.processMouseWheelEvent Process mouse wheel events that are delivered to thisScrollPane
by scrolling an appropriate amount. -
Event Registration Methods Modifier and Type Method and Description addComponentListener Adds the specified component listener to receive component events from this component.addContainerListener Adds the specified container listener to receive container events from this container.addFocusListener Adds the specified focus listener to receive focus events from this component when this component gains input focus.addHierarchyBoundsListener Adds the specified hierarchy bounds listener to receive hierarchy bounds events from this component when the hierarchy to which this container belongs changes.addHierarchyListener Adds the specified hierarchy listener to receive hierarchy changed events from this component when the hierarchy to which this container belongs changes.addInputMethodListener Adds the specified input method listener to receive input method events from this component.addKeyListener Adds the specified key listener to receive key events from this component.addMouseListener Adds the specified mouse listener to receive mouse events from this component.addMouseMotionListener Adds the specified mouse motion listener to receive mouse motion events from this component.addMouseWheelListener Adds the specified mouse wheel listener to receive mouse wheel events from this component.addPropertyChangeListener Adds a PropertyChangeListener to the listener list.addPropertyChangeListener Adds a PropertyChangeListener to the listener list for a specific property.getComponentListeners Returns an array of all the component listeners registered on this component.getContainerListeners Returns an array of all the container listeners registered on this container.getFocusListeners Returns an array of all the focus listeners registered on this component.getHierarchyBoundsListeners Returns an array of all the hierarchy bounds listeners registered on this component.getHierarchyListeners Returns an array of all the hierarchy listeners registered on this component.getInputMethodListeners Returns an array of all the input method listeners registered on this component.getKeyListeners Returns an array of all the key listeners registered on this component.getMouseListeners Returns an array of all the mouse listeners registered on this component.getMouseMotionListeners Returns an array of all the mouse motion listeners registered on this component.getMouseWheelListeners Returns an array of all the mouse wheel listeners registered on this component.getPropertyChangeListeners Returns an array of all the property change listeners registered on this component.getPropertyChangeListeners Returns an array of all the listeners which have been associated with the named property.removeComponentListener Removes the specified component listener so that it no longer receives component events from this component.removeContainerListener Removes the specified container listener so it no longer receives container events from this container.removeFocusListener Removes the specified focus listener so that it no longer receives focus events from this component.removeHierarchyBoundsListener Removes the specified hierarchy bounds listener so that it no longer receives hierarchy bounds events from this component.removeHierarchyListener Removes the specified hierarchy listener so that it no longer receives hierarchy changed events from this component.removeInputMethodListener Removes the specified input method listener so that it no longer receives input method events from this component.removeKeyListener Removes the specified key listener so that it no longer receives key events from this component.removeMouseListener Removes the specified mouse listener so that it no longer receives mouse events from this component.removeMouseMotionListener Removes the specified mouse motion listener so that it no longer receives mouse motion events from this component.removeMouseWheelListener Removes the specified mouse wheel listener so that it no longer receives mouse wheel events from this component.removePropertyChangeListener Removes a PropertyChangeListener from the listener list.removePropertyChangeListener Removes aPropertyChangeListener
from the listener list for a specific property. -
Keyboard Focus Methods Modifier and Type Method and Description areFocusTraversalKeysSet Returns whether the Set of focus traversal keys for the given focus traversal operation has been explicitly defined for this Container.getFocusCycleRootAncestor Returns the Container which is the focus cycle root of this Component's focus traversal cycle.getFocusTraversalKeys Returns the Set of focus traversal keys for a given traversal operation for this Container.getFocusTraversalKeysEnabled Returns whether focus traversal keys are enabled for this Component.getFocusTraversalPolicy Returns the focus traversal policy that will manage keyboard traversal of this Container's children, or null if this Container is not a focus cycle root.gotFocus Deprecated. As of JDK version 1.1, replaced by processFocusEvent(FocusEvent).hasFocus Returnstrue
if thisComponent
is the focus owner.isFocusable Returns whether this Component can be focused.isFocusCycleRoot Returns whether this Container is the root of a focus traversal cycle.isFocusCycleRoot Returns whether the specified Container is the focus cycle root of this Container's focus traversal cycle.isFocusOwner Returnstrue
if thisComponent
is the focus owner.isFocusTraversable Deprecated. As of 1.4, replaced byisFocusable()
.isFocusTraversalPolicyProvider Returns whether this container provides focus traversal policy.isFocusTraversalPolicySet Returns whether the focus traversal policy has been explicitly set for this Container.lostFocus Deprecated. As of JDK version 1.1, replaced by processFocusEvent(FocusEvent).nextFocus Deprecated. As of JDK version 1.1, replaced by transferFocus().requestFocus Requests that this Component get the input focus, and that this Component's top-level ancestor become the focused Window.requestFocus Requests that thisComponent
get the input focus, and that thisComponent
's top-level ancestor become the focusedWindow
.requestFocusInWindow Requests that this Component get the input focus, if this Component's top-level ancestor is already the focused Window.requestFocusInWindow Requests that thisComponent
get the input focus, if thisComponent
's top-level ancestor is already the focusedWindow
.setFocusable Sets the focusable state of this Component to the specified value.setFocusCycleRoot Sets whether this Container is the root of a focus traversal cycle.setFocusTraversalKeys Sets the focus traversal keys for a given traversal operation for this Container.setFocusTraversalKeysEnabled Sets whether focus traversal keys are enabled for this Component.setFocusTraversalPolicy Sets the focus traversal policy that will manage keyboard traversal of this Container's children, if this Container is a focus cycle root.setFocusTraversalPolicyProvider Sets whether this container will be used to provide focus traversal policy.transferFocus Transfers the focus to the next component, as though this Component were the focus owner.transferFocusBackward Transfers the focus to the previous component, as though this Component were the focus owner.transferFocusDownCycle Transfers the focus down one focus traversal cycle.transferFocusUpCycle Transfers the focus up one focus traversal cycle. -
Graphics Methods Modifier and Type Method and Description getFontMetrics Gets the font metrics for the specified font.getGraphics Creates a graphics context for this component.getGraphicsConfiguration Gets theGraphicsConfiguration
associated with thisComponent
.getLocationOnScreen Gets the location of this component in the form of a point specifying the component's top-left corner in the screen's coordinate space.getMousePosition Returns the position of the mouse pointer in thisComponent
's coordinate space if theComponent
is directly under the mouse pointer, otherwise returnsnull
.getToolkit Gets the toolkit of this component. -
Hierarchy Methods Modifier and Type Method and Description add Appends the specified component to the end of this container.add Adds the specified component to this container at the given position.add Adds the specified component to the end of this container.add Adds the specified component to this container with the specified constraints at the specified index.add Adds the specified component to this container.addImpl Adds the specified component to this scroll pane container.countComponents Deprecated. As of JDK version 1.1, replaced by getComponentCount().getComponent Gets the nth component in this container.getComponentCount Gets the number of components in this panel.getComponents Gets all the components in this container.getComponentZOrder Returns the z-order index of the component inside the container.isAncestorOf Checks if the component is contained in the component hierarchy of this container.remove Removes the specified component from this container.remove Removes the component, specified byindex
, from this container.removeAll Removes all the components from this container.setComponentZOrder Moves the specified component to the specified z-order index in the container. -
Image Methods Modifier and Type Method and Description checkImage Returns the status of the construction of a screen representation of the specified image.checkImage Returns the status of the construction of a screen representation of the specified image.createImage Creates an image from the specified image producer.createImage Creates an off-screen drawable image to be used for double buffering.createVolatileImage Creates a volatile off-screen drawable image to be used for double buffering.createVolatileImage Creates a volatile off-screen drawable image, with the given capabilities.imageUpdate Repaints the component when the image has changed.prepareImage Prepares an image for rendering on this component.prepareImage Prepares an image for rendering on this component at the specified width and height. -
Layout Methods Modifier and Type Method and Description bounds Deprecated. As of JDK version 1.1, replaced bygetBounds()
.contains Checks whether this component "contains" the specified point, wherex
andy
are defined to be relative to the coordinate system of this component.contains Checks whether this component "contains" the specified point, where the point's x and y coordinates are defined to be relative to the coordinate system of this component.doLayout Lays out this container by resizing its child to its preferred size.findComponentAt Locates the visible child component that contains the specified position.findComponentAt Locates the visible child component that contains the specified point.getAlignmentX Returns the alignment along the x axis.getAlignmentY Returns the alignment along the y axis.getBaseline Returns the baseline.getBaselineResizeBehavior Returns an enum indicating how the baseline of the component changes as the size changes.getBounds Gets the bounds of this component in the form of aRectangle
object.getBounds Stores the bounds of this component into "return value" rv and return rv.getComponentAt Locates the component that contains the x,y position.getComponentAt Gets the component that contains the specified point.getHeight Returns the current height of this component.getInsets Determines the insets of this container, which indicate the size of the container's border.getLayout Gets the layout manager for this container.getLocation Gets the location of this component in the form of a point specifying the component's top-left corner.getLocation Stores the x,y origin of this component into "return value" rv and return rv.getMaximumSize Returns the maximum size of this container.getMinimumSize Returns the minimum size of this container.getMousePosition Returns the position of the mouse pointer in thisContainer
's coordinate space if theContainer
is under the mouse pointer, otherwise returnsnull
.getPreferredSize Returns the preferred size of this container.getSize Returns the size of this component in the form of aDimension
object.getSize Stores the width/height of this component into "return value" rv and return rv.getWidth Returns the current width of this component.getX Returns the current x coordinate of the components origin.getY Returns the current y coordinate of the components origin.insets Deprecated. As of JDK version 1.1, replaced bygetInsets()
.inside Deprecated. As of JDK version 1.1, replaced by contains(int, int).invalidate Invalidates the container.isMaximumSizeSet Returns true if the maximum size has been set to a non-null
value otherwise returns false.isMinimumSizeSet Returns whether or notsetMinimumSize
has been invoked with a non-null value.isPreferredSizeSet Returns true if the preferred size has been set to a non-null
value otherwise returns false.isValid Determines whether this component is valid.isValidateRoot Indicates if this container is a validate root.layout Deprecated. As of JDK version 1.1, replaced bydoLayout()
.locate Deprecated. As of JDK version 1.1, replaced bygetComponentAt(int, int)
.location Deprecated. As of JDK version 1.1, replaced bygetLocation()
.minimumSize Deprecated. As of JDK version 1.1, replaced bygetMinimumSize()
.move Deprecated. As of JDK version 1.1, replaced bysetLocation(int, int)
.preferredSize Deprecated. As of JDK version 1.1, replaced bygetPreferredSize()
.reshape Deprecated. As of JDK version 1.1, replaced bysetBounds(int, int, int, int)
.resize Deprecated. As of JDK version 1.1, replaced bysetSize(Dimension)
.resize Deprecated. As of JDK version 1.1, replaced bysetSize(int, int)
.revalidate Revalidates the component hierarchy up to the nearest validate root.setBounds Moves and resizes this component.setBounds Moves and resizes this component to conform to the new bounding rectangler
.setLayout Sets the layout manager for this container.setLocation Moves this component to a new location.setLocation Moves this component to a new location.setMaximumSize Sets the maximum size of this component to a constant value.setMinimumSize Sets the minimum size of this component to a constant value.setPreferredSize Sets the preferred size of this component to a constant value.setSize Resizes this component so that it has widthd.width
and heightd.height
.setSize Resizes this component so that it has widthwidth
and heightheight
.size Deprecated. As of JDK version 1.1, replaced bygetSize()
.validate Validates this container and all of its subcomponents.validateTree Recursively descends the container tree and recomputes the layout for any subtrees marked as needing it (those marked as invalid). -
Painting Methods Modifier and Type Method and Description getIgnoreRepaint paint Paints the container.paintAll Paints this component and all of its subcomponents.paintComponents Paints each of the components in this container.repaint Repaints this component.repaint Repaints the specified rectangle of this component.repaint Repaints the component.repaint Repaints the specified rectangle of this component withintm
milliseconds.setIgnoreRepaint Sets whether or not paint messages received from the operating system should be ignored.update Updates the container. -
Printing Methods Modifier and Type Method and Description list Prints a listing of this component to the standard system output streamSystem.out
.list Prints a listing of this component to the specified output stream.list Prints a listing of this container to the specified output stream.list Prints a listing to the specified print writer.list Prints out a list, starting at the specified indentation, to the specified print writer.print Prints the container.printAll Prints this component and all of its subcomponents.printComponents Prints the component in this scroll pane. -
Other Methods Modifier and Type Method and Description add Adds the specified popup menu to the component.addNotify Creates the scroll pane's peer.eventTypeEnabled If wheel scrolling is enabled, we return true for MouseWheelEventsgetDropTarget Gets theDropTarget
associated with thisComponent
.getHAdjustable Returns theScrollPaneAdjustable
object which represents the state of the horizontal scrollbar.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.getInputContext Gets the input context used by this component for handling the communication with input methods when text is entered in this component.getInputMethodRequests Gets the input method request handler which supports requests from input methods for this component.getPeer Deprecated. As of JDK version 1.1, programs should not directly manipulate peers; replaced byboolean isDisplayable()
.getScrollbarDisplayPolicy Returns the display policy for the scrollbars.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.getTreeLock Gets this component's locking object (the object that owns the thread synchronization monitor) for AWT component-tree and layout operations.getVAdjustable Returns theScrollPaneAdjustable
object which represents the state of the vertical scrollbar.getViewportSize Returns the current size of the scroll pane's view port.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.isWheelScrollingEnabled Indicates whether or not scrolling will take place in response to the mouse wheel.paramString Returns a string representing the state of thisScrollPane
.remove Removes the specified popup menu from the component.removeNotify Makes this Container undisplayable by removing its connection to its native screen resource.setDropTarget Associate aDropTarget
with this component.setScrollPosition Scrolls to the specified position within the child component.setScrollPosition Scrolls to the specified position within the child component.setWheelScrollingEnabled Enables/disables scrolling in response to movement of the mouse wheel.toString Returns a string representation of this component and its values.
-
-