[Chapter 19] Scrollbar
Author: John Zukowski
Date: Thu Jul 31 15:15:59 1997

#

| Chapter 19 java.awt Reference |

# Scrollbar

## Name

Scrollbar

##

## Description

The `Scrollbar` is a `Component` that provides the means to get and set values within a predetermined range. For example, a scrollbar could be used for a volume control. Scrollbars are most frequently used to help users manipulate areas too large to be displayed on the screen (pre version 1.1) or to set a value within an integer range.

## Class Definition

    public class java.awt.Scrollbar
        extends java.awt.Component
        implements java.awt.Adjustable {

      // Constants
      public final static int HORIZONTAL;
      public final static int VERTICAL;

      // Constructors
      public Scrollbar();
      public Scrollbar (int orientation);
      public Scrollbar (int orientation, int value, int visible, int minimum,
        int maximum);

      // Instance Methods
      public void addAdjustmentListener (AdjustmentListener l);
      public void addNotify();
      public int getBlockIncrement();
      public int getLineIncrement();
      public int getMaximum();
      public int getMinimum();
      public int getOrientation();
      public int getPageIncrement();
      public int getUnitIncrement();
      public int getValue();
      public int getVisible();
      public int getVisibleAmount();
      public void removeAdjustmentListener (AdjustmentListener l);
      public synchronized void setBlockIncrement (int v);
      public void setLineIncrement (int amount);
      public synchronized void setMaximum (int newMaximum);
      public synchronized void setMinimum (int newMinimum);
      public synchronized void setOrientation (int orientation);
      public void setPageIncrement (int amount);
      public synchronized void setUnitIncrement(int v);
      public synchronized void setValue (int value);
      public synchronized void setValues (int value, int visible,
        int minimum, int maximum);
      public synchronized void setVisibleAmount (int newAmount);

      // Protected Instance Methods
      protected String paramString();
      protected void processAdjustmentEvent (AdjustmentEvent e);
      protected void processEvent (AWTEvent e);
    }

## Constants

### HORIZONTAL

#### public final static int HORIZONTAL

Constant used for a `Scrollbar` with a horizontal orientation.

### VERTICAL

#### public final static int VERTICAL

Constant used for a `Scrollbar` with a vertical orientation.

## Constructors

### Scrollbar

#### public Scrollbar()

Description

  Constructs a vertical `Scrollbar` object; slider size, minimum value, maximum value, and initial value are all zero.

#### public Scrollbar (int orientation)

Parameters

  orientation

    `Scrollbar` constant designating direction.

Throws

  IllegalArgumentException

    If `orientation` is invalid.

Description

  Constructs a `Scrollbar` object, in the designated direction; slider size, minimum value, maximum value, and initial value are all zero.

#### public Scrollbar (int orientation, int value, int visible, int minimum, int maximum)

Parameters

  orientation

    `Scrollbar` constant designating direction.

  value

    Initial value of `Scrollbar`.

  visible

    Initial slider size.

  minimum

    Initial minimum value.

  maximum

    Initial maximum value.

Throws

  IllegalArgumentException

    If `orientation` is invalid.

Description

  Constructs a `Scrollbar` object with the given values.

## Instance Methods

### addAdjustmentListener

#### public void addAdjustmentListener (AdjustmentListener l)

Parameters

  l

    An object that implements the `AdjustmentListener` interface.

Implements

  `Adjustable.addAdjustmentListener()`

Description

  Add a listener for adjustment event.

### addNotify

#### public void addNotify()

Overrides

  `Component.addNotify()`

Description

  Creates `Scrollbar`'s peer.

### getBlockIncrement

#### public int getBlockIncrement()

Implements

  `Adjustable.getBlockIncrement()`

Returns

  The amount to scroll when a paging area is selected.

### getLineIncrement

#### public int getLineIncrement()

Returns

  The amount to scroll when one of the arrows at the ends of the scrollbar is selected. Replaced by `getUnitIncrement()`.

### getMaximum

#### public int getMaximum()

Implements

  `Adjustable.getMaximum()`

Returns

  The maximum value that the `Scrollbar` can take.

### getMinimum

#### public int getMinimum()

Implements

  `Adjustable.getMinimum()`

Returns

  The minimum value that the `Scrollbar` can take.

### getOrientation

#### public int getOrientation()

Implements

  `Adjustable.getOrientation()`

Returns

  A constant representing the direction of the `Scrollbar`.

### getPageIncrement

#### public int getPageIncrement()

Returns

  The amount to scroll when a paging area is selected. Replaced with `getBlockIncrement()`.

### getUnitIncrement

#### public int getUnitIncrement()

Implements

  `Adjustable.getUnitIncrement()`

Returns

  The amount to scroll when one of the arrows at the ends of the scrollbar is selected.

### getValue

#### public int getValue()

Implements

  `Adjustable.getValue()`

Returns

  The current setting for the `Scrollbar`.

### getVisible

#### public int getVisible()

Returns

  The current visible setting (i.e., size) for the slider. Replaced by `getVisibleAmount()`.

### getVisibleAmount

#### public int getVisibleAmount()

Implements

  `Adjustable.getVisibleAmount()`

Returns

  The current visible setting (i.e., size) for the slider.

### removeAdjustmentListener

#### public void removeAdjustmentListener (AdjustmentListener l)

Parameters

  l

    One of this `Scrollbar`'s `AdjustmentListener`s.

Implements

  `Adjustable.removeAdjustmentListener()`

Description

  Remove an adjustment event listener.

### setBlockIncrement

#### public synchronized void setBlockIncrement (int amount)

Parameters

  amount

    New paging increment amount.

Implements

  `Adjustable.setBlockIncrement()`

Description

  Changes the block increment amount for the `Scrollbar`; the default block increment is 10.

### setLineIncrement

#### public void setLineIncrement (int amount)

Parameters

  amount

    New line increment amount.

Description

  Changes the line increment amount for the `Scrollbar`. The default line increment is 1. Replaced by `setUnitIncrement(int)`.

### setMaximum

#### public synchronized void setMaximum (int newMaximum)

Parameters

  newMaximum

    New maximum value.

Implements

  `Adjustable.setMaximum()`

Description

  Changes the maximum value for the `Scrollbar`.

### setMinimum

#### public synchronized void setMinimum (int newMinimum)

Parameters

  newMinimum

    New minimum value.

Implements

  `Adjustable.setMinimum()`

Description

  Changes the minimum value for the `Scrollbar`.

### setOrientation

#### public synchronized void setOrientation (int orientation)

Parameters

  orientation

    One of the orientation constants `HORIZONTAL` or `VERTICAL`.

Description

  Changes the orientation of the `Scrollbar`.

### setPageIncrement

#### public void setPageIncrement (int amount)

Parameters

  amount

    New paging increment amount.

Description

  Changes the paging increment amount for the `Scrollbar`; the default page increment is 10. Replaced by `setBlockIncrement(int)`.

### setUnitIncrement

#### public synchronized void setUnitIncrement (int amount)

Parameters

  amount

    New line increment amount.

Implements

  `Adjustable.setUnitIncrement()`

Description

  Changes the unit increment amount for the `Scrollbar`. The default unit increment is 1.

### setValue

#### public synchronized void setValue (int value)

Parameters

  value

    New `Scrollbar` value.

Implements

  `Adjustable.setValue()`

Description

  Changes the current value of the `Scrollbar`.

### setValues

#### public synchronized void setValues (int value, int visible, int minimum, int maximum)

Parameters

  value

    New `Scrollbar` value.

  visible

    New slider width.

  minimum

    New minimum value for `Scrollbar`.

  maximum

    New maximum value for `Scrollbar`.

Description

  Changes the settings of the `Scrollbar` to the given amounts.

### setVisibleAmount

#### public synchronized void setVisibleAmount (int newAmount)

Parameters

  newAmount

    New amount visible.

Implements

  `Adjustable.setVisibleAmount()`

Description

  Changes the current visible amount of the `Scrollbar`.

## Protected Instance Methods

### paramString

#### protected String paramString()

Returns

  String with current settings of `Scrollbar`.

Overrides

  `Component.paramString()`

Description

  Helper method for `toString()` to generate string of current settings.

### processAdjustmentEvent

#### protected void processAdjustmentEvent (AdjustmentEvent e)

Parameters

  e

    The adjustment event to process.

Description

  Adjustment events are passed to this method for processing. Normally, this method is called by `processEvent()`.

### processEvent

#### protected void processEvent (AWTEvent e)

Parameters

  e

    The event to process.

Description

  Low level `AWTEvent`s are passed to this method for processing.

## See Also

`Adjustable`, `Component`, `String`

ScrollPane |  | Shape