javax.swing
Class JScrollBar

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JScrollBar
All Implemented Interfaces:
Adjustable, ImageObserver, MenuContainer, Serializable, Accessible
Direct Known 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
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
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, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, 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, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setNextFocusableComponent, setOpaque, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

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 Detail

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 Detail

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.

getUI

public ScrollBarUI getUI()
This method returns the UI that is being used with this scrollbar.

Returns:
The scrollbar's current UI.

updateUI

public void updateUI()
This method changes the UI to be the default for the current look and feel.

Overrides:
updateUI in class JComponent

getUIClassID

public String getUIClassID()
This method returns an identifier to choose the correct UI delegate for the scrollbar.

Overrides:
getUIClassID in class JComponent
Returns:
The identifer to choose the UI delegate; "ScrollBarUI"
See Also:
JComponent.setUI(javax.swing.plaf.ComponentUI), JComponent.updateUI()

getOrientation

public int getOrientation()
This method returns the orientation of the scrollbar.

Specified by:
getOrientation in interface Adjustable
Returns:
The orientation of the scrollbar.
See Also:
Adjustable.HORIZONTAL, Adjustable.VERTICAL, Adjustable.NO_ORIENTATION

setOrientation

public void setOrientation(int orientation)
This method sets the orientation of the scrollbar.

Parameters:
orientation - The orientation of the scrollbar.

getModel

public BoundedRangeModel getModel()
This method returns the model being used with the scrollbar.

Returns:
The scrollbar's model.

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.

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.

setUnitIncrement

public void setUnitIncrement(int unitIncrement)
This method sets the unitIncrement property.

Specified by:
setUnitIncrement in interface Adjustable
Parameters:
unitIncrement - The new unitIncrement.

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.

setBlockIncrement

public void setBlockIncrement(int blockIncrement)
This method sets the blockIncrement property.

Specified by:
setBlockIncrement in interface Adjustable
Parameters:
blockIncrement - The new blockIncrement.

getUnitIncrement

public int getUnitIncrement()
This method returns the unitIncrement.

Specified by:
getUnitIncrement in interface Adjustable
Returns:
The unitIncrement.

getBlockIncrement

public int getBlockIncrement()
This method returns the blockIncrement.

Specified by:
getBlockIncrement in interface Adjustable
Returns:
The blockIncrement.

getValue

public int getValue()
This method returns the value of the scrollbar.

Specified by:
getValue in interface Adjustable
Returns:
The value of the scrollbar.

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.

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).

setVisibleAmount

public void setVisibleAmount(int extent)
This method sets the visible amount (AKA extent).

Specified by:
setVisibleAmount in interface Adjustable
Parameters:
extent - The visible amount (AKA extent).

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.

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.

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.

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.

getValueIsAdjusting

public boolean getValueIsAdjusting()
This method returns the model's isAjusting value.

Returns:
The model's isAdjusting value.

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.
newExtent - The new extent.
newMin - The new minimum.
newMax - The new maximum.

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.
See Also:
AdjustmentEvent

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.
See Also:
AdjustmentEvent

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.

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..

getMinimumSize

public Dimension getMinimumSize()
This method returns the minimum size for this scroll bar.

Overrides:
getMinimumSize in class JComponent
Returns:
The minimum size.
See Also:
Component.setMinimumSize(java.awt.Dimension), Component.getMinimumSize(), Component.isMinimumSizeSet(), ComponentUI.getMinimumSize(JComponent)

getMaximumSize

public Dimension getMaximumSize()
This method returns the maximum size for this scroll bar.

Overrides:
getMaximumSize in class JComponent
Returns:
The maximum size.
See Also:
Component.setMaximumSize(java.awt.Dimension), Component.getMaximumSize(), Component.isMaximumSizeSet(), ComponentUI.getMaximumSize(JComponent)

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 class JComponent
Parameters:
x - Whether the scrollbar is enabled.
See Also:
Component.isEnabled(), Component.isLightweight()

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 class JComponent
Returns:
A string describing the attributes of the JScrollBar.

getAccessibleContext

public AccessibleContext getAccessibleContext()
Returns the object that provides accessibility features for this JScrollBar component.

Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in class JComponent
Returns:
The accessible context (an instance of JScrollBar.AccessibleJScrollBar).