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.
javax.swing
class JScrollBar
- All Implemented Interfaces:
- Adjustable, MenuContainer, ImageObserver, Serializable, Accessible, TransferHandler.HasGetTransferHandler
- Direct Known Subclasses:
- JScrollPane.ScrollBar
-
Most common ways to construct:
-
JScrollPane scrollPane = …;
JScrollBar hBar = scrollPane.getHorizontalScrollBar();
Based on 30 examples
-
-
JScrollPane scrollPane = …;
JScrollBar vBar = scrollPane.getVerticalScrollBar();
Based on 30 examples
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 JavaBeansTM
has been added to the java.beans
package.
Please see {@link java.beans.XMLEncoder}.
Nested Class Summary |
protected class |
This class implements accessibility support for the
JScrollBar class. |
Constructor Summary |
Creates a vertical scrollbar with the following initial values:
|
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 |
void |
Adds an AdjustmentListener.
|
protected void |
Notify listeners that the scrollbar's model has changed.
|
AccessibleContext |
Gets the AccessibleContext associated with this JScrollBar.
|
AdjustmentListener[] |
Returns an array of all the AdjustmentListener s added
to this JScrollBar with addAdjustmentListener().
|
int |
For backwards compatibility with java.awt.Scrollbar.
|
int |
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.
|
Dimension |
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).
|
Dimension |
The scrollbar is flexible along it's scrolling axis and
rigid along the other axis.
|
BoundedRangeModel |
Returns data model that handles the scrollbar's four
fundamental properties: minimum, maximum, value, extent.
|
int |
Returns the component's orientation (horizontal or vertical).
|
ScrollBarUI |
Returns the delegate that implements the look and feel for
this component.
|
String |
Returns the name of the LookAndFeel class for this component.
|
int |
For backwards compatibility with java.awt.Scrollbar.
|
int |
Returns the amount to change the scrollbar's value by,
given a unit up/down request.
|
int |
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 |
Sets the blockIncrement property.
|
void |
Enables the component so that the knob position can be changed.
|
void |
Sets the model's maximum property.
|
void |
Sets the model's minimum property.
|
void |
Sets the model that handles the scrollbar's four
fundamental properties: minimum, maximum, value, extent.
|
void |
Set the scrollbar's orientation to either VERTICAL or
HORIZONTAL.
|
void |
Sets the L&F object that renders this component.
|
void |
Sets the unitIncrement property.
|
void |
Sets the scrollbar's value.
|
void |
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 |
Set the model's extent property.
|
void |
Overrides JComponent.updateUI .
|
Methods inherited from class javax.swing.JComponent |
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, 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, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI |
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 |
blockIncrement
protected int blockIncrement
-
model
protected BoundedRangeModel model
-
The model that represents the scrollbar's minimum, maximum, extent
(aka "visibleAmount") and current value.
orientation
protected int orientation
-
unitIncrement
protected int unitIncrement
-
JScrollBar
public JScrollBar()
-
Creates a vertical scrollbar with the following initial values:
minimum = 0
maximum = 100
value = 0
extent = 10
JScrollBar
public JScrollBar(int orientation)
-
Creates a scrollbar with the specified orientation
and the following initial values:
minimum = 0
maximum = 100
value = 0
extent = 10
- Parameters:
orientation
JScrollBar
public JScrollBar(int orientation,
int value,
int extent,
int min,
int max)
-
Creates a scrollbar with the specified orientation,
value, extent, minimum, and maximum.
The "extent" is the size of the viewable area. It is also known
as the "visible amount".
Note: Use setBlockIncrement
to set the block
increment to a size slightly smaller than the view's extent.
That way, when the user jumps the knob to an adjacent position,
one or two lines of the original contents remain in view.
- Parameters:
orientation
value
extent
min
max
addAdjustmentListener
public void addAdjustmentListener(AdjustmentListener l)
-
Adds an AdjustmentListener. Adjustment listeners are notified
each time the scrollbar's model changes. Adjustment events are
provided for backwards compatibility with java.awt.Scrollbar.
Note that the AdjustmentEvents type property will always have a
placeholder value of AdjustmentEvent.TRACK because all changes
to a BoundedRangeModels value are considered equivalent. To change
the value of a BoundedRangeModel one just sets its value property,
i.e. model.setValue(123). No information about the origin of the
change, e.g. it's a block decrement, is provided. We don't try
fabricate the origin of the change here.
- Parameters:
l
- the AdjustmentLister to add
fireAdjustmentValueChanged
protected void fireAdjustmentValueChanged(int id,
int type,
int value)
-
Notify listeners that the scrollbar's model has changed.
- Parameters:
id
type
value
getAccessibleContext
public AccessibleContext getAccessibleContext()
-
Gets the AccessibleContext associated with this JScrollBar.
For JScrollBar, the AccessibleContext takes the form of an
AccessibleJScrollBar.
A new AccessibleJScrollBar instance is created if necessary.
- Overrides:
getAccessibleContext
in class JComponent
- Returns:
- an AccessibleJScrollBar that serves as the
AccessibleContext of this JScrollBar
getAdjustmentListeners
public AdjustmentListener[] getAdjustmentListeners()
-
Returns an array of all the
AdjustmentListener
s added
to this JScrollBar with addAdjustmentListener().
- Returns:
- all of the
AdjustmentListener
s added or an empty
array if no listeners have been added
getBlockIncrement
public int getBlockIncrement()
-
For backwards compatibility with java.awt.Scrollbar.
getBlockIncrement
public int getBlockIncrement(int direction)
-
Returns the amount to change the scrollbar's value by,
given a block (usually "page") up/down request. A ScrollBarUI
implementation typically calls this method when the user clicks
above or below the scrollbar "knob" to change the value
up or down by large amount. Subclasses my override this
method to compute a value, e.g. the change required to scroll
up or down one paragraph in a text document.
The JScrollPane component creates scrollbars (by default)
that override this method and delegate to the viewports
Scrollable view, if it has one. The Scrollable interface
provides a more specialized version of this method.
- Parameters:
direction
- is -1 or 1 for up/down respectively
- Returns:
- the value of the blockIncrement property
getMaximum
public int getMaximum()
-
The maximum value of the scrollbar is maximum - extent.
- Returns:
- the value of the model's maximum property
getMaximumSize
public Dimension getMaximumSize()
-
The scrollbar is flexible along it's scrolling axis and
rigid along the other axis.
- Overrides:
getMaximumSize
in class JComponent
getMinimum
public int getMinimum()
-
Returns the minimum value supported by the scrollbar
(usually zero).
- Returns:
- the value of the model's minimum property
getMinimumSize
public Dimension getMinimumSize()
-
The scrollbar is flexible along it's scrolling axis and
rigid along the other axis.
- Overrides:
getMinimumSize
in class JComponent
getModel
public BoundedRangeModel getModel()
-
Returns data model that handles the scrollbar's four
fundamental properties: minimum, maximum, value, extent.
getOrientation
public int getOrientation()
-
Returns the component's orientation (horizontal or vertical).
- Returns:
- VERTICAL or HORIZONTAL
getUI
public ScrollBarUI getUI()
-
Returns the delegate that implements the look and feel for
this component.
getUIClassID
public String getUIClassID()
-
Returns the name of the LookAndFeel class for this component.
- Overrides:
getUIClassID
in class JComponent
- Returns:
- "ScrollBarUI"
getUnitIncrement
public int getUnitIncrement()
-
For backwards compatibility with java.awt.Scrollbar.
getUnitIncrement
public int getUnitIncrement(int direction)
-
Returns the amount to change the scrollbar's value by,
given a unit up/down request. A ScrollBarUI implementation
typically calls this method when the user clicks on a scrollbar
up/down arrow and uses the result to update the scrollbar's
value. Subclasses my override this method to compute
a value, e.g. the change required to scroll up or down one
(variable height) line text or one row in a table.
The JScrollPane component creates scrollbars (by default)
that override this method and delegate to the viewports
Scrollable view, if it has one. The Scrollable interface
provides a more specialized version of this method.
- Parameters:
direction
- is -1 or 1 for up/down respectively
- Returns:
- the value of the unitIncrement property
getValue
public int getValue()
-
Returns the scrollbar's value.
- Returns:
- the model's value property
getValueIsAdjusting
public boolean getValueIsAdjusting()
-
True if the scrollbar knob is being dragged.
- Returns:
- the value of the model's valueIsAdjusting property
getVisibleAmount
public int getVisibleAmount()
-
Returns the scrollbar's extent, aka its "visibleAmount". In many
scrollbar look and feel implementations the size of the
scrollbar "knob" or "thumb" is proportional to the extent.
- Returns:
- the value of the model's extent property
paramString
protected String paramString()
-
Returns a string representation of this JScrollBar. 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 JComponent
- Returns:
- a string representation of this JScrollBar.
removeAdjustmentListener
public void removeAdjustmentListener(AdjustmentListener l)
-
Removes an AdjustmentEvent listener.
- Parameters:
l
- the AdjustmentLister to remove
setBlockIncrement
public void setBlockIncrement(int blockIncrement)
-
Sets the blockIncrement property.
Note, that if the argument is equal to the value of Integer.MIN_VALUE,
the most look and feels will not provide the scrolling to the right/down.
- Parameters:
blockIncrement
setEnabled
public void setEnabled(boolean x)
-
Enables the component so that the knob position can be changed.
When the disabled, the knob position cannot be changed.
- Overrides:
setEnabled
in class JComponent
- Parameters:
x
- a boolean value, where true enables the component and
false disables it
setMaximum
public void setMaximum(int maximum)
-
Sets the model's maximum property. Note that the scrollbar's value
can only be set to maximum - extent.
- Parameters:
maximum
setMinimum
public void setMinimum(int minimum)
-
Sets the model's minimum property.
- Parameters:
minimum
setModel
public void setModel(BoundedRangeModel newModel)
-
Sets the model that handles the scrollbar's four
fundamental properties: minimum, maximum, value, extent.
- Parameters:
newModel
setOrientation
public void setOrientation(int orientation)
-
Set the scrollbar's orientation to either VERTICAL or
HORIZONTAL.
- Parameters:
orientation
setUI
public void setUI(ScrollBarUI ui)
-
Sets the L&F object that renders this component.
- Parameters:
ui
- the ScrollBarUI
L&F object
setUnitIncrement
public void setUnitIncrement(int unitIncrement)
-
Sets the unitIncrement property.
Note, that if the argument is equal to the value of Integer.MIN_VALUE,
the most look and feels will not provide the scrolling to the right/down.
- Parameters:
unitIncrement
setValue
public void setValue(int value)
-
Sets the scrollbar's value. This method just forwards the value
to the model.
- Parameters:
value
setValueIsAdjusting
public void setValueIsAdjusting(boolean b)
-
Sets the model's valueIsAdjusting property. Scrollbar look and
feel implementations should set this property to true when
a knob drag begins, and to false when the drag ends. The
scrollbar model will not generate ChangeEvents while
valueIsAdjusting is true.
- Parameters:
b
setValues
public void setValues(int newValue,
int newExtent,
int newMin,
int newMax)
-
Sets the four BoundedRangeModel properties after forcing
the arguments to obey the usual constraints:
minimum <= value <= value+extent <= maximum
- Parameters:
newValue
newExtent
newMin
newMax
setVisibleAmount
public void setVisibleAmount(int extent)
-
Set the model's extent property.
- Parameters:
extent
updateUI
public void updateUI()
-
Overrides
JComponent.updateUI
.
- Overrides:
updateUI
in class JComponent
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/.