javax.swing

Class JScrollBar

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.
Nested Class Summary
protected classJScrollBar.AccessibleJScrollBar
Provides the accessibility features for the JScrollBar component.
Field Summary
protected intblockIncrement
How much the thumb moves when moving in a block.
protected BoundedRangeModelmodel
The model that holds the scroll bar's data.
protected intorientation
The orientation of the scroll bar.
protected intunitIncrement
How much the thumb moves when moving in a unit.
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
voidaddAdjustmentListener(AdjustmentListener listener)
This method adds an AdjustmentListener to the scroll bar.
protected voidfireAdjustmentValueChanged(int id, int type, int value)
This method is called to fired AdjustmentEvents to the listeners of this scroll bar.
AccessibleContextgetAccessibleContext()
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.
intgetBlockIncrement(int direction)
The method returns how much the scrollbar's value should change for a block increment depending on the given direction.
intgetBlockIncrement()
This method returns the blockIncrement.
intgetMaximum()
This method returns the maximum value of the scrollbar.
DimensiongetMaximumSize()
This method returns the maximum size for this scroll bar.
intgetMinimum()
This method returns the minimum value of the scrollbar.
DimensiongetMinimumSize()
This method returns the minimum size for this scroll bar.
BoundedRangeModelgetModel()
This method returns the model being used with the scrollbar.
intgetOrientation()
This method returns the orientation of the scrollbar.
ScrollBarUIgetUI()
This method returns the UI that is being used with this scrollbar.
StringgetUIClassID()
This method returns an identifier to choose the correct UI delegate for the scrollbar.
intgetUnitIncrement(int direction)
This method returns how much the scrollbar's value should change for a unit increment depending on the given direction.
intgetUnitIncrement()
This method returns the unitIncrement.
intgetValue()
This method returns the value of the scrollbar.
booleangetValueIsAdjusting()
This method returns the model's isAjusting value.
intgetVisibleAmount()
This method returns the visible amount (AKA extent).
protected StringparamString()
Returns a string describing the attributes for the JScrollBar component, for use in debugging.
voidremoveAdjustmentListener(AdjustmentListener listener)
This method removes an AdjustmentListener from the scroll bar.
voidsetBlockIncrement(int blockIncrement)
This method sets the blockIncrement property.
voidsetEnabled(boolean x)
This method overrides the setEnabled in JComponent.
voidsetMaximum(int maximum)
This method sets the maximum value of the scrollbar.
voidsetMinimum(int minimum)
This method sets the minimum value of the scrollbar.
voidsetModel(BoundedRangeModel newModel)
This method sets the model to use with the scrollbar.
voidsetOrientation(int orientation)
This method sets the orientation of the scrollbar.
voidsetUI(ScrollBarUI ui)
This method sets the UI of this scrollbar to the given UI.
voidsetUnitIncrement(int unitIncrement)
This method sets the unitIncrement property.
voidsetValue(int value)
This method changes the value of the scrollbar.
voidsetValueIsAdjusting(boolean b)
This method sets the model's isAdjusting value.
voidsetValues(int newValue, int newExtent, int newMin, int newMax)
This method sets the value, extent, minimum and maximum.
voidsetVisibleAmount(int extent)
This method sets the visible amount (AKA extent).
voidupdateUI()
This method changes the UI to be the default for the current look and feel.

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

addAdjustmentListener

public void addAdjustmentListener(AdjustmentListener listener)
This method adds an AdjustmentListener to the scroll bar.

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.

Returns: The accessible context (an instance of {@link 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(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.

getBlockIncrement

public int getBlockIncrement()
This method returns the blockIncrement.

Returns: The blockIncrement.

getMaximum

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

Returns: The maximum value of the scrollbar.

getMaximumSize

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

Returns: The maximum size.

getMinimum

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

Returns: The minimum value of the scrollbar.

getMinimumSize

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

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.

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.

Returns: The identifer to choose the UI delegate; "ScrollBarUI"

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.

getUnitIncrement

public int getUnitIncrement()
This method returns the unitIncrement.

Returns: The unitIncrement.

getValue

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

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.

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.

Returns: A string describing the attributes of the JScrollBar.

removeAdjustmentListener

public void removeAdjustmentListener(AdjustmentListener listener)
This method removes an AdjustmentListener from the scroll bar.

Parameters: listener The listener to remove.

setBlockIncrement

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

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.

Parameters: x Whether the scrollbar is enabled.

setMaximum

public void setMaximum(int maximum)
This method sets the maximum value of the scrollbar.

Parameters: maximum The maximum value of the scrollbar.

setMinimum

public void setMinimum(int minimum)
This method sets the minimum value of the scrollbar.

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.

Parameters: unitIncrement The new unitIncrement.

setValue

public void setValue(int value)
This method changes the value of the scrollbar.

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

setVisibleAmount

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

Parameters: extent The visible amount (AKA extent).

updateUI

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