java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JScrollBar
- All Implemented Interfaces:
Adjustable
,ImageObserver
,MenuContainer
,Serializable
,Accessible
- Direct Known Subclasses:
JScrollPane.ScrollBar
@JavaBean(defaultProperty="UI",
description="A component that helps determine the visible content range of an area.")
public class JScrollBar
extends JComponent
implements Adjustable, Accessible
An implementation of a scrollbar. The user positions the knob in the
scrollbar to determine the contents of the viewing area. The
program typically adjusts the display so that the end of the
scrollbar represents the end of the displayable contents, or 100%
of the contents. The start of the scrollbar is the beginning of the
displayable contents, or 0%. The position of the knob within
those bounds then translates to the corresponding percentage of
the displayable contents.
Typically, as the position of the knob in the scrollbar changes a corresponding change is made to the position of the JViewport on the underlying view, changing the contents of the JViewport.
Warning: Swing is not thread safe. For more information see Swing's Threading Policy.
Warning:
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeans
has been added to the java.beans
package.
Please see XMLEncoder
.
- Since:
- 1.2
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected class
This class implements accessibility support for theJScrollBar
class.Nested classes/interfaces declared in class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces declared in class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces declared in class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
protected BoundedRangeModel
The model that represents the scrollbar's minimum, maximum, extent (aka "visibleAmount") and current value.protected int
protected int
Fields declared in class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields declared in class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields declared in interface java.awt.Adjustable
HORIZONTAL, NO_ORIENTATION, VERTICAL
Fields declared in interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a vertical scrollbar with the following initial values:JScrollBar
(int orientation) Creates a scrollbar with the specified orientation and the following initial values:JScrollBar
(int orientation, int value, int extent, int min, int max) Creates a scrollbar with the specified orientation, value, extent, minimum, and maximum. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds an AdjustmentListener.protected void
fireAdjustmentValueChanged
(int id, int type, int value) Notify listeners that the scrollbar's model has changed.Gets the AccessibleContext associated with this JScrollBar.Returns an array of all theAdjustmentListener
s added to this JScrollBar with addAdjustmentListener().int
For backwards compatibility with java.awt.Scrollbar.int
getBlockIncrement
(int direction) Returns the amount to change the scrollbar's value by, given a block (usually "page") up/down request.int
The maximum value of the scrollbar is maximum - extent.The scrollbar is flexible along it's scrolling axis and rigid along the other axis.int
Returns the minimum value supported by the scrollbar (usually zero).The scrollbar is flexible along it's scrolling axis and rigid along the other axis.getModel()
Returns data model that handles the scrollbar's four fundamental properties: minimum, maximum, value, extent.int
Returns the component's orientation (horizontal or vertical).getUI()
Returns the delegate that implements the look and feel for this component.Returns the name of the LookAndFeel class for this component.int
For backwards compatibility with java.awt.Scrollbar.int
getUnitIncrement
(int direction) Returns the amount to change the scrollbar's value by, given a unit up/down request.int
getValue()
Returns the scrollbar's value.boolean
True if the scrollbar knob is being dragged.int
Returns the scrollbar's extent, aka its "visibleAmount".protected String
Returns a string representation of this JScrollBar.void
Removes an AdjustmentEvent listener.void
setBlockIncrement
(int blockIncrement) Sets the blockIncrement property.void
setEnabled
(boolean x) Enables the component so that the knob position can be changed.void
setMaximum
(int maximum) Sets the model's maximum property.void
setMinimum
(int minimum) Sets the model's minimum property.void
setModel
(BoundedRangeModel newModel) Sets the model that handles the scrollbar's four fundamental properties: minimum, maximum, value, extent.void
setOrientation
(int orientation) Set the scrollbar's orientation to either VERTICAL or HORIZONTAL.void
setUI
(ScrollBarUI ui) Sets the L&F object that renders this component.void
setUnitIncrement
(int unitIncrement) Sets the unitIncrement property.void
setValue
(int value) Sets the scrollbar's value.void
setValueIsAdjusting
(boolean b) Sets the model's valueIsAdjusting property.void
setValues
(int newValue, int newExtent, int newMin, int newMax) Sets the four BoundedRangeModel properties after forcing the arguments to obey the usual constraints:void
setVisibleAmount
(int extent) Set the model's extent property.void
updateUI()
OverridesJComponent.updateUI
.Methods declared in class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately,