javax.swing

Class JScrollBar

Implemented Interfaces:
Accessible, Adjustable, ImageObserver, MenuContainer, Serializable
Known Direct Subclasses:
JScrollPane.ScrollBar

public class JScrollBar
extends JComponent
implements Adjustable, Accessible

The JScrollBar. Two buttons control how the values that the scroll bar can take. You can also drag the thumb or click the track to move the scroll bar. Typically, the JScrollBar is used with other components to translate the value of the bar to the viewable contents of the other components.
See Also:
Serialized Form

Nested Class Summary

protected class
JScrollBar.AccessibleJScrollBar
Provides the accessibility features for the JScrollBar component.

Nested classes/interfaces inherited from class javax.swing.JComponent

JComponent.AccessibleJComponent

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

protected int
blockIncrement
How much the thumb moves when moving in a block.
protected BoundedRangeModel
model
The model that holds the scroll bar's data.
protected int
orientation
The orientation of the scroll bar.
protected int
unitIncrement
How much the thumb moves when moving in a unit.

Fields inherited from class javax.swing.JComponent

TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW, accessibleContext, listenerList, ui

Fields inherited from class java.awt.Component

BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT

Fields inherited from interface java.awt.Adjustable

HORIZONTAL, NO_ORIENTATION, VERTICAL

Fields inherited from interface java.awt.image.ImageObserver

ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH

Constructor Summary

JScrollBar()
Creates a new horizontal JScrollBar object with a minimum of 0, a maxmium of 100, a value of 0 and an extent of 10.
JScrollBar(int orientation)
Creates a new JScrollBar object with a minimum of 0, a maximum of 100, a value of 0, an extent of 10 and the given orientation.
JScrollBar(int orientation, int value, int extent, int min, int max)
Creates a new JScrollBar object with the given orientation, value, min, max, and extent.

Method Summary

void
addAdjustmentListener(AdjustmentListener listener)
This method adds an AdjustmentListener to the scroll bar.
protected void
fireAdjustmentValueChanged(int id, int type, int value)
This method is called to fired AdjustmentEvents to the listeners of this scroll bar.
AccessibleContext
getAccessibleContext()
Returns the object that provides accessibility features for this JScrollBar component.
AdjustmentListener[]
getAdjustmentListeners()
This method returns an arry of all AdjustmentListeners listening to this scroll bar.
int
getBlockIncrement()
This method returns the blockIncrement.
int
getBlockIncrement(int direction)
The method returns how much the scrollbar's value should change for a block increment depending on the given direction.
int
getMaximum()
This method returns the maximum value of the scrollbar.
Dimension
getMaximumSize()
This method returns the maximum size for this scroll bar.
int
getMinimum()
This method returns the minimum value of the scrollbar.
Dimension
getMinimumSize()
This method returns the minimum size for this scroll bar.
BoundedRangeModel
getModel()
This method returns the model being used with the scrollbar.
int
getOrientation()
This method returns the orientation of the scrollbar.
ScrollBarUI
getUI()
This method returns the UI that is being used with this scrollbar.
String
getUIClassID()
This method returns an identifier to choose the correct UI delegate for the scrollbar.
int
getUnitIncrement()
This method returns the unitIncrement.
int
getUnitIncrement(int direction)
This method returns how much the scrollbar's value should change for a unit increment depending on the given direction.
int
getValue()
This method returns the value of the scrollbar.
boolean
getValueIsAdjusting()
This method returns the model's isAjusting value.
int
getVisibleAmount()
This method returns the visible amount (AKA extent).
protected String
paramString()
Returns a string describing the attributes for the JScrollBar component, for use in debugging.
void
removeAdjustmentListener(AdjustmentListener listener)
This method removes an AdjustmentListener from the scroll bar.
void
setBlockIncrement(int blockIncrement)
This method sets the blockIncrement property.
void
setEnabled(boolean x)
This method overrides the setEnabled in JComponent.
void
setMaximum(int maximum)
This method sets the maximum value of the scrollbar.
void
setMinimum(int minimum)
This method sets the minimum value of the scrollbar.
void
setModel(BoundedRangeModel newModel)
This method sets the model to use with the scrollbar.
void
setOrientation(int orientation)
This method sets the orientation of the scrollbar.
void
setUI(ScrollBarUI ui)
This method sets the UI of this scrollbar to the given UI.
void
setUnitIncrement(int unitIncrement)
This method sets the unitIncrement property.
void
setValue(int value)
This method changes the value of the scrollbar.
void
setValueIsAdjusting(boolean b)
This method sets the model's isAdjusting value.
void
setValues(int newValue, int newExtent, int newMin, int newMax)
This method sets the value, extent, minimum and maximum.
void
setVisibleAmount(int extent)
This method sets the visible amount (AKA extent).
void
updateUI()
This method changes the UI to be the default for the current look and feel.

Methods inherited from class javax.swing.JComponent

addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, extends EventListener> T[] getListeners, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, 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, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setNextFocusableComponent, setOpaque, 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, 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

blockIncrement

protected int blockIncrement
How much the thumb moves when moving in a block.

model

protected BoundedRangeModel model
The model that holds the scroll bar's data.

orientation

protected int orientation
The orientation of the scroll bar.

unitIncrement

protected int unitIncrement
How much the thumb moves when moving in a unit.

Constructor Details

JScrollBar

public JScrollBar()
Creates a new horizontal JScrollBar object with a minimum of 0, a maxmium of 100, a value of 0 and an extent of 10.

JScrollBar

public JScrollBar(int orientation)
Creates a new JScrollBar object with a minimum of 0, a maximum of 100, a value of 0, an extent of 10 and the given orientation.
Parameters:
orientation - The orientation of the JScrollBar.

JScrollBar

public JScrollBar(int orientation,
                  int value,
                  int extent,
                  int min,
                  int max)
Creates a new JScrollBar object with the given orientation, value, min, max, and extent.
Parameters:
orientation - The orientation to use.
value - The value to use.
extent - The extent to use.
min - The minimum value of the scrollbar.
max - The maximum value of the scrollbar.

Method Details

addAdjustmentListener

public void addAdjustmentListener(AdjustmentListener listener)
This method adds an AdjustmentListener to the scroll bar.
Specified by:
addAdjustmentListener in interface Adjustable
Parameters:
listener - The listener to add.

fireAdjustmentValueChanged

protected void fireAdjustmentValueChanged(int id,
                                          int type,
                                          int value)
This method is called to fired AdjustmentEvents to the listeners of this scroll bar. All AdjustmentEvents that are fired will have an ID of ADJUSTMENT_VALUE_CHANGED and a type of TRACK.
Parameters:
id - The ID of the adjustment event.
type - The Type of change.
value - The new value for the property that was changed..

getAccessibleContext

public AccessibleContext getAccessibleContext()
Returns the object that provides accessibility features for this JScrollBar component.
Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in interface JComponent
Returns:
The accessible context (an instance of JScrollBar.AccessibleJScrollBar).

getAdjustmentListeners

public AdjustmentListener[] getAdjustmentListeners()
This method returns an arry of all AdjustmentListeners listening to this scroll bar.
Returns:
An array of AdjustmentListeners listening to this scroll bar.

getBlockIncrement

public int getBlockIncrement()
This method returns the blockIncrement.
Specified by:
getBlockIncrement in interface Adjustable
Returns:
The blockIncrement.

getBlockIncrement

public int getBlockIncrement(int direction)
The method returns how much the scrollbar's value should change for a block increment depending on the given direction.
Parameters:
direction - The direction to scroll in.
Returns:
The amount the scrollbar's value will change given the direction.

getMaximum

public int getMaximum()
This method returns the maximum value of the scrollbar.
Specified by:
getMaximum in interface Adjustable
Returns:
The maximum value of the scrollbar.

getMaximumSize

public Dimension getMaximumSize()
This method returns the maximum size for this scroll bar.
Overrides:
getMaximumSize in interface JComponent
Returns:
The maximum size.

getMinimum

public int getMinimum()
This method returns the minimum value of the scrollbar.
Specified by:
getMinimum in interface Adjustable
Returns:
The minimum value of the scrollbar.

getMinimumSize

public Dimension getMinimumSize()
This method returns the minimum size for this scroll bar.
Overrides:
getMinimumSize in interface JComponent
Returns:
The minimum size.

getModel

public BoundedRangeModel getModel()
This method returns the model being used with the scrollbar.
Returns:
The scrollbar's model.

getOrientation

public int getOrientation()
This method returns the orientation of the scrollbar.
Specified by:
getOrientation in interface Adjustable
Returns:
The orientation of the scrollbar.

getUI

public ScrollBarUI getUI()
This method returns the UI that is being used with this scrollbar.
Returns:
The scrollbar's current UI.

getUIClassID

public String getUIClassID()
This method returns an identifier to choose the correct UI delegate for the scrollbar.
Overrides:
getUIClassID in interface JComponent
Returns:
The identifer to choose the UI delegate; "ScrollBarUI"

getUnitIncrement

public int getUnitIncrement()
This method returns the unitIncrement.
Specified by:
getUnitIncrement in interface Adjustable
Returns:
The unitIncrement.

getUnitIncrement

public int getUnitIncrement(int direction)
This method returns how much the scrollbar's value should change for a unit increment depending on the given direction.
Parameters:
direction - The direction to scroll in.
Returns:
The amount the scrollbar's value will change given the direction.

getValue

public int getValue()
This method returns the value of the scrollbar.
Specified by:
getValue in interface Adjustable
Returns:
The value of the scrollbar.

getValueIsAdjusting

public boolean getValueIsAdjusting()
This method returns the model's isAjusting value.
Returns:
The model's isAdjusting value.

getVisibleAmount

public int getVisibleAmount()
This method returns the visible amount (AKA extent). The visible amount can be used by UI delegates to determine the size of the thumb.
Specified by:
getVisibleAmount in interface Adjustable
Returns:
The visible amount (AKA extent).

paramString

protected String paramString()
Returns a string describing the attributes for the JScrollBar component, for use in debugging. The return value is guaranteed to be non-null, but the format of the string may vary between implementations.
Overrides:
paramString in interface JComponent
Returns:
A string describing the attributes of the JScrollBar.

removeAdjustmentListener

public void removeAdjustmentListener(AdjustmentListener listener)
This method removes an AdjustmentListener from the scroll bar.
Specified by:
removeAdjustmentListener in interface Adjustable
Parameters:
listener - The listener to remove.

setBlockIncrement

public void setBlockIncrement(int blockIncrement)
This method sets the blockIncrement property.
Specified by:
setBlockIncrement in interface Adjustable
Parameters:
blockIncrement - The new blockIncrement.

setEnabled

public void setEnabled(boolean x)
This method overrides the setEnabled in JComponent. When the scroll bar is disabled, the knob cannot be moved.
Overrides:
setEnabled in interface JComponent
Parameters:
x - Whether the scrollbar is enabled.

setMaximum

public void setMaximum(int maximum)
This method sets the maximum value of the scrollbar.
Specified by:
setMaximum in interface Adjustable
Parameters:
maximum - The maximum value of the scrollbar.

setMinimum

public void setMinimum(int minimum)
This method sets the minimum value of the scrollbar.
Specified by:
setMinimum in interface Adjustable
Parameters:
minimum - The minimum value of the scrollbar.

setModel

public void setModel(BoundedRangeModel newModel)
This method sets the model to use with the scrollbar.
Parameters:
newModel - The new model to use with the scrollbar.

setOrientation

public void setOrientation(int orientation)
This method sets the orientation of the scrollbar.
Parameters:
orientation - The orientation of the scrollbar.

setUI

public void setUI(ScrollBarUI ui)
This method sets the UI of this scrollbar to the given UI.
Parameters:
ui - The UI to use with this scrollbar.

setUnitIncrement

public void setUnitIncrement(int unitIncrement)
This method sets the unitIncrement property.
Specified by:
setUnitIncrement in interface Adjustable
Parameters:
unitIncrement - The new unitIncrement.

setValue

public void setValue(int value)
This method changes the value of the scrollbar.
Specified by:
setValue in interface Adjustable
Parameters:
value - The new value of the scrollbar.

setValueIsAdjusting

public void setValueIsAdjusting(boolean b)
This method sets the model's isAdjusting value.
Parameters:
b - The new isAdjusting value.

setValues

public void setValues(int newValue,
                      int newExtent,
                      int newMin,
                      int newMax)
This method sets the value, extent, minimum and maximum.
Parameters:
newValue - The new value.