java.awt

Class Scrollbar

public class Scrollbar extends Component implements Accessible, Adjustable

This class implements a scrollbar widget.
Nested Class Summary
protected classScrollbar.AccessibleAWTScrollBar
This class provides accessibility support for the scrollbar.
Field Summary
static intHORIZONTAL
Constant indicating that a scrollbar is horizontal.
static intVERTICAL
Constant indicating that a scrollbar is vertical.
Constructor Summary
Scrollbar()
Initializes a new instance of Scrollbar with a vertical orientation and default values for all other parameters.
Scrollbar(int orientation)
Initializes a new instance of Scrollbar with the specified orientation and default values for all other parameters.
Scrollbar(int orientation, int value, int visibleAmount, int minimum, int maximum)
Initializes a new instance of Scrollbar with the specified parameters.
Method Summary
voidaddAdjustmentListener(AdjustmentListener listener)
Adds a new adjustment listener to the list of registered listeners for this object.
voidaddNotify()
Notifies this object to create its native peer.
AccessibleContextgetAccessibleContext()
Gets the AccessibleContext associated with this Scrollbar.
AdjustmentListener[]getAdjustmentListeners()
Returns an array of all registered adjustment listeners.
intgetBlockIncrement()
Returns the value added or subtracted when the user activates the scrollbar scroll by a "block" amount.
intgetLineIncrement()
Returns the value added or subtracted when the user selects the scrollbar scroll by a "unit" amount control.
<T extends EventListener> T[]getListeners(Class<T> listenerType)
Returns an array of all the objects currently registered as FooListeners upon this Scrollbar.
intgetMaximum()
Returns the maximum value for this scrollbar.
intgetMinimum()
Returns the minimum value for this scrollbar.
intgetOrientation()
Returns the orientation constant for this object.
intgetPageIncrement()
Returns the value added or subtracted when the user selects the scrollbar scroll by a "block" amount control.
intgetUnitIncrement()
Returns the value added or subtracted when the user activates the scrollbar scroll by a "unit" amount.
intgetValue()
Returns the current value for this scrollbar.
booleangetValueIsAdjusting()
Returns true if the value is in the process of changing.
intgetVisible()
Returns the width of the scrollbar's thumb, in units relative to the maximum and minimum value of the scrollbar.
intgetVisibleAmount()
Returns the width of the scrollbar's thumb, in units relative to the maximum and minimum value of the scrollbar.
protected StringparamString()
Returns a debugging string for this object.
protected voidprocessAdjustmentEvent(AdjustmentEvent event)
Processes adjustment events for this object by dispatching them to any registered listeners.
protected voidprocessEvent(AWTEvent event)
Processes events for this scrollbar.
voidremoveAdjustmentListener(AdjustmentListener listener)
Removes the specified listener from the list of registered listeners for this object.
voidsetBlockIncrement(int blockIncrement)
Sets the value added or subtracted to the scrollbar value when the user selects the scroll by a "block" amount control.
voidsetLineIncrement(int lineIncrement)
Sets the value added or subtracted to the scrollbar value when the user selects the scroll by a "unit" amount control.
voidsetMaximum(int maximum)
Sets the maximum value for this scrollbar to the specified value.
voidsetMinimum(int minimum)
Sets the minimum value for this scrollbar to the specified value.
voidsetOrientation(int orientation)
Sets the orientation of this scrollbar to the specified value.
voidsetPageIncrement(int pageIncrement)
Sets the value added or subtracted to the scrollbar value when the user selects the scroll by a "block" amount control.
voidsetUnitIncrement(int unitIncrement)
Sets the value added or subtracted to the scrollbar value when the user selects the scroll by a "unit" amount control.
voidsetValue(int value)
Sets the current value for this scrollbar to the specified value.
voidsetValueIsAdjusting(boolean valueIsAdjusting)
Sets the value of valueIsAdjusting.
voidsetValues(int value, int visibleAmount, int minimum, int maximum)
Sets the current value, visible amount, minimum, and maximum for this scrollbar.
voidsetVisibleAmount(int visibleAmount)
Sets the width of the scrollbar's thumb, in units relative to the maximum and minimum value of the scrollbar.

Field Detail

HORIZONTAL

public static final int HORIZONTAL
Constant indicating that a scrollbar is horizontal.

VERTICAL

public static final int VERTICAL
Constant indicating that a scrollbar is vertical.

Constructor Detail

Scrollbar

public Scrollbar()
Initializes a new instance of Scrollbar with a vertical orientation and default values for all other parameters.

Throws: HeadlessException If GraphicsEnvironment.isHeadless() is true,

Scrollbar

public Scrollbar(int orientation)
Initializes a new instance of Scrollbar with the specified orientation and default values for all other parameters. The orientation must be either the constant HORIZONTAL or VERTICAL from this class. An incorrect value will throw an exception.

Parameters: orientation The orientation of this scrollbar.

Throws: HeadlessException If GraphicsEnvironment.isHeadless() is true, IllegalArgumentException If the orientation value is not valid.

Scrollbar

public Scrollbar(int orientation, int value, int visibleAmount, int minimum, int maximum)
Initializes a new instance of Scrollbar with the specified parameters. The orientation must be either the constant HORIZONTAL or VERTICAL. An incorrect value will throw an exception. Inconsistent values for other parameters are silently corrected to valid values.

Parameters: orientation The orientation of this scrollbar. value The initial value of the scrollbar. visibleAmount The width of the scrollbar thumb. minimum The minimum value of the scrollbar. maximum The maximum value of the scrollbar.

Throws: HeadlessException If GraphicsEnvironment.isHeadless() is true, IllegalArgumentException If the orientation value is not valid.

Method Detail

addAdjustmentListener

public void addAdjustmentListener(AdjustmentListener listener)
Adds a new adjustment listener to the list of registered listeners for this object.

Parameters: listener The listener to add.

addNotify

public void addNotify()
Notifies this object to create its native peer.

getAccessibleContext

public AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with this Scrollbar. The context is created, if necessary.

Returns: the associated context

getAdjustmentListeners

public AdjustmentListener[] getAdjustmentListeners()
Returns an array of all registered adjustment listeners.

getBlockIncrement

public int getBlockIncrement()
Returns the value added or subtracted when the user activates the scrollbar scroll by a "block" amount.

Returns: The block increment value.

getLineIncrement

public int getLineIncrement()

Deprecated: This method is deprecated in favor of getUnitIncrement().

Returns the value added or subtracted when the user selects the scrollbar scroll by a "unit" amount control.

Returns: The unit increment value.

getListeners

public <T extends EventListener> T[] getListeners(Class<T> listenerType)
Returns an array of all the objects currently registered as FooListeners upon this Scrollbar. FooListeners are registered using the addFooListener method.

Throws: ClassCastException If listenerType doesn't specify a class or interface that implements java.util.EventListener.

getMaximum

public int getMaximum()
Returns the maximum value for this scrollbar.

Returns: The maximum value for this scrollbar.

getMinimum

public int getMinimum()
Returns the minimum value for this scrollbar.

Returns: The minimum value for this scrollbar.

getOrientation

public int getOrientation()
Returns the orientation constant for this object.

Returns: The orientation constant for this object.

getPageIncrement

public int getPageIncrement()

Deprecated: This method is deprecated in favor of getBlockIncrement().

Returns the value added or subtracted when the user selects the scrollbar scroll by a "block" amount control.

Returns: The block increment value.

getUnitIncrement

public int getUnitIncrement()
Returns the value added or subtracted when the user activates the scrollbar scroll by a "unit" amount.

Returns: The unit increment value.

getValue

public int getValue()
Returns the current value for this scrollbar.

Returns: The current value for this scrollbar.

getValueIsAdjusting

public boolean getValueIsAdjusting()
Returns true if the value is in the process of changing.

Since: 1.4

getVisible

public int getVisible()

Deprecated: This method is deprecated in favor of getVisibleAmount().

Returns the width of the scrollbar's thumb, in units relative to the maximum and minimum value of the scrollbar.

Returns: The width of the scrollbar's thumb.

getVisibleAmount

public int getVisibleAmount()
Returns the width of the scrollbar's thumb, in units relative to the maximum and minimum value of the scrollbar.

Returns: The width of the scrollbar's thumb.

paramString

protected String paramString()
Returns a debugging string for this object.

Returns: A debugging string for this object.

processAdjustmentEvent

protected void processAdjustmentEvent(AdjustmentEvent event)
Processes adjustment events for this object by dispatching them to any registered listeners. Note that this method will only be called if adjustment events are enabled. This will happen automatically if any listeners are registered. Otherwise, it can be enabled by a call to enableEvents().

Parameters: event The event to process.

processEvent

protected void processEvent(AWTEvent event)
Processes events for this scrollbar. It does this by calling processAdjustmentEvent() if the event is an instance of AdjustmentEvent, otherwise it calls the superclass to process the event.

Parameters: event The event to process.

removeAdjustmentListener

public void removeAdjustmentListener(AdjustmentListener listener)
Removes the specified listener from the list of registered listeners for this object.

Parameters: listener The listener to remove.

setBlockIncrement

public void setBlockIncrement(int blockIncrement)
Sets the value added or subtracted to the scrollbar value when the user selects the scroll by a "block" amount control.

Parameters: blockIncrement The new block increment amount.

setLineIncrement

public void setLineIncrement(int lineIncrement)

Deprecated: This method is deprecated in favor of setUnitIncrement().

Sets the value added or subtracted to the scrollbar value when the user selects the scroll by a "unit" amount control.

Parameters: lineIncrement The new unit increment amount.

setMaximum

public void setMaximum(int maximum)
Sets the maximum value for this scrollbar to the specified value. If the value is less than the current minimum value, it is silent set to equal the minimum value.

Parameters: maximum The new maximum value for this scrollbar.

setMinimum

public void setMinimum(int minimum)
Sets the minimum value for this scrollbar to the specified value. If this is not consistent with the current value and maximum, it is silently adjusted to be consistent.

Parameters: minimum The new minimum value for this scrollbar.

setOrientation

public void setOrientation(int orientation)
Sets the orientation of this scrollbar to the specified value. This value must be either the constant HORIZONTAL or VERTICAL from this class or an exception will be thrown.

Parameters: orientation The new orientation value.

Throws: IllegalArgumentException If the orientation value is not valid.

setPageIncrement

public void setPageIncrement(int pageIncrement)

Deprecated: This method is deprecated in favor of setBlockIncrement().

Sets the value added or subtracted to the scrollbar value when the user selects the scroll by a "block" amount control.

Parameters: pageIncrement The new block increment amount.

setUnitIncrement

public void setUnitIncrement(int unitIncrement)
Sets the value added or subtracted to the scrollbar value when the user selects the scroll by a "unit" amount control.

Parameters: unitIncrement The new unit increment amount.

setValue

public void setValue(int value)
Sets the current value for this scrollbar to the specified value. If this is inconsistent with the minimum and maximum values for this scrollbar, the value is silently adjusted.

Parameters: value The new value for this scrollbar.

setValueIsAdjusting

public void setValueIsAdjusting(boolean valueIsAdjusting)
Sets the value of valueIsAdjusting.

Since: 1.4

setValues

public void setValues(int value, int visibleAmount, int minimum, int maximum)
Sets the current value, visible amount, minimum, and maximum for this scrollbar. These values are adjusted to be internally consistent if necessary.

Parameters: value The new value for this scrollbar. visibleAmount The new visible amount for this scrollbar. minimum The new minimum value for this scrollbar. maximum The new maximum value for this scrollbar.

setVisibleAmount

public void setVisibleAmount(int visibleAmount)
Sets the width of the scrollbar's thumb, in units relative to the maximum and minimum value of the scrollbar.

Parameters: visibleAmount The new visible amount value of the scrollbar.