站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > JDK 5 Documentation v1.1.8, Java 2 SDK 英文文档

Class java.awt.Scrollbar - JDK 5 Documentation v1.1.8, Java 2 SDK 英文文档

All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class java.awt.Scrollbar

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Scrollbar

public class Scrollbar
extends Component
implements Adjustable
The Scrollbar class embodies a scroll bar, a familiar user-interface object. A scroll bar provides a convenient means for allowing a user to select from a range of values. The following three vertical scroll bars could be used as slider controls to pick the red, green, and blue components of a color:

Each scroll bar in this example could be created with code similar to the following:


 redSlider=new Scrollbar(Scrollbar.VERTICAL, 0, 1, 0, 255);
 add(redSlider);
 

Alternatively, a scroll bar can represent a range of values. For example, if a scroll bar is used for scrolling through text, the width of the "bubble" or "thumb" can represent the amount of text that is visible. Here is an example of a scroll bar that represents a range:

The value range represented by the bubble is the visible range of the scroll bar. The horizontal scroll bar in this example could be created with code like the following:


 ranger = new Scrollbar(Scrollbar.HORIZONTAL, 0, 64, 0, 255);
 add(ranger);
 

Note that the maximum value above, 255, is the maximum value for the scroll bar's bubble. The actual width of the scroll bar's track is 255 + 64. When the scroll bar is set to its maximum value, the left side of the bubble is at 255, and the right side is at 255 + 64.

Normally, the user changes the value of the scroll bar by making a gesture with the mouse. For example, the user can drag the scroll bar's bubble up and down, or click in the scroll bar's unit increment or block increment areas. Keyboard gestures can also be mapped to the scroll bar. By convention, the Page Up and Page Down keys are equivalent to clicking in the scroll bar's block increment and block decrement areas.

When the user changes the value of the scroll bar, the scroll bar receives an instance of AdjustmentEvent. The scroll bar processes this event, passing it along to any registered listeners.

Any object that wishes to be notified of changes to the scroll bar's value should implement AdjustmentListener, an interface defined in the package java.awt.event. Listeners can be added and removed dynamically by calling the methods addAdjustmentListener and removeAdjustmentListener.

The AdjustmentEvent class defines five types of adjustment event, listed here:

The JDK 1.0 event system is supported for backwards compatibility, but its use with newer versions of JDK is discouraged. The fives types of adjustment event introduced with JDK 1.1 correspond to the five event types that are associated with scroll bars in previous JDK versions. The following list gives the adjustment event type, and the corresponding JDK 1.0 event type it replaces.

See Also:
AdjustmentEvent, AdjustmentListener

Variable Index

 o HORIZONTAL
A constant that indicates a horizontal scroll bar.
 o VERTICAL
A constant that indicates a vertical scroll bar.

Constructor Index

 o Scrollbar()
Constructs a new vertical scroll bar.
 o Scrollbar(int)
Constructs a new scroll bar with the specified orientation.
 o Scrollbar(int, int, int, int, int)
Constructs a new scroll bar with the specified orientation, initial value, page size, and minimum and maximum values.

Method Index

 o addAdjustmentListener(AdjustmentListener)
Adds the specified adjustment listener to receive instances of AdjustmentEvent from this scroll bar.
 o addNotify()
Creates the Scrollbar's peer.
 o getBlockIncrement()
Gets the block increment of this scroll bar.
 o getLineIncrement()
Deprecated.
 o getMaximum()
Gets the maximum value of this scroll bar.
 o getMinimum()
Gets the minimum value of this scroll bar.
 o getOrientation()
Determines the orientation of this scroll bar.
 o getPageIncrement()
Deprecated.
 o getUnitIncrement()
Gets the unit increment for this scrollbar.
 o getValue()
Gets the current value of this scroll bar.
 o getVisible()
Deprecated.
 o getVisibleAmount()
Gets the visible amount of this scroll bar.
 o paramString()
Returns the parameter string representing the state of this scroll bar.
 o processAdjustmentEvent(AdjustmentEvent)
Processes adjustment events occurring on this scrollbar by dispatching them to any registered AdjustmentListener objects.
 o processEvent(AWTEvent)
Processes events on this scroll bar.
 o removeAdjustmentListener(AdjustmentListener)
Removes the specified adjustment listener so that it no longer receives instances of AdjustmentEvent from this scroll bar.
 o setBlockIncrement(int)
Sets the block increment for this scroll bar.
 o setLineIncrement(int)
Deprecated.
 o setMaximum(int)
Sets the maximum value of this scroll bar.
 o setMinimum(int)
Sets the minimum value of this scroll bar.
 o setOrientation(int)
Sets the orientation for this scroll bar.
 o setPageIncrement(int)
Deprecated.
 o setUnitIncrement(int)
Sets the unit increment for this scroll bar.
 o setValue(int)
Sets the value of this scroll bar to the specified value.
 o setValues(int, int, int, int)
Sets the values of four properties for this scroll bar.
 o setVisibleAmount(int)
Sets the visible amount of this scroll bar.

Variables

 o HORIZONTAL
 public static final int HORIZONTAL
A constant that indicates a horizontal scroll bar.

 o VERTICAL
 public static final int VERTICAL
A constant that indicates a vertical scroll bar.

Constructors

 o Scrollbar
 public Scrollbar()
Constructs a new vertical scroll bar.

 o Scrollbar
 public Scrollbar(int orientation)
Constructs a new scroll bar with the specified orientation.

The orientation argument must take one of the two values Scrollbar.HORIZONTAL, or Scrollbar.VERTICAL, indicating a horizontal or vertical scroll bar, respectively.

Parameters:
orientation - indicates the orientation of the scroll bar.
Throws: IllegalArgumentException
when an illegal value for the orientation argument is supplied.
 o Scrollbar
 public Scrollbar(int orientation,
                  int value,
                  int visible,
                  int minimum,
                  int maximum)
Constructs a new scroll bar with the specified orientation, initial value, page size, and minimum and maximum values.

The orientation argument must take one of the two values Scrollbar.HORIZONTAL, or Scrollbar.VERTICAL, indicating a horizontal or vertical scroll bar, respectively.

If the specified maximum value is less than the minimum value, it is changed to be the same as the minimum value. If the initial value is lower than the minimum value, it is changed to be the minimum value; if it is greater than the maximum value, it is changed to be the maximum value.

Parameters:
orientation - indicates the orientation of the scroll bar.
value - the initial value of the scroll bar.
visible - the size of the scroll bar's bubble, representing the visible portion; the scroll bar uses this value when paging up or down by a page.
minimum - the minimum value of the scroll bar.
maximum - the maximum value of the scroll bar.

Methods

 o addNotify
 public void addNotify()
Creates the Scrollbar's peer. The peer allows you to modify the appearance of the Scrollbar without changing any of its functionality.

Overrides:
addNotify in class Component
 o getOrientation
 public int getOrientation()
Determines the orientation of this scroll bar.

Returns:
the orientation of this scroll bar, either Scrollbar.HORIZONTAL or Scrollbar.VERTICAL.
See Also:
setOrientation
 o setOrientation
 public void setOrientation(int orientation)
Sets the orientation for this scroll bar.

Parameters:
the - orientation of this scroll bar, either Scrollbar.HORIZONTAL or Scrollbar.VERTICAL.
Throws: IllegalArgumentException
if the value supplied for orientation is not a legal value.
See Also:
getOrientation
 o getValue
 public int getValue()
Gets the current value of this scroll bar.

Returns:
the current value of this scroll bar.
See Also:
getMinimum, getMaximum
 o setValue
 public void setValue(int newValue)
Sets the value of this scroll bar to the specified value.

If the value supplied is less than the current minimum or greater than the current maximum, then one of those values is substituted, as appropriate.

Normally, a program should change a scroll bar's value only by calling setValues. The setValues method simultaneously and synchronously sets the minimum, maximum, visible amount, and value properties of a scroll bar, so that they are mutually consistent.

Parameters:
newValue - the new value of the scroll bar.
See Also:
setValues, getValue, getMinimum, getMaximum
 o getMinimum
 public int getMinimum()
Gets the minimum value of this scroll bar.

Returns:
the minimum value of this scroll bar.
See Also:
getValue, getMaximum
 o setMinimum
 public void setMinimum(int newMinimum)
Sets the minimum value of this scroll bar.

Normally, a program should change a scroll bar's minimum value only by calling setValues. The setValues method simultaneously and synchronously sets the minimum, maximum, visible amount, and value properties of a scroll bar, so that they are mutually consistent.

Parameters:
newMinimum - the new minimum value for this scroll bar.
See Also:
setValues, setMaximum
 o getMaximum
 public int getMaximum()
Gets the maximum value of this scroll bar.

Returns:
the maximum value of this scroll bar.
See Also:
getValue, getMinimum
 o setMaximum
 public void setMaximum(int newMaximum)
Sets the maximum value of this scroll bar.

Normally, a program should change a scroll bar's maximum value only by calling setValues. The setValues method simultaneously and synchronously sets the minimum, maximum, visible amount, and value properties of a scroll bar, so that they are mutually consistent.

Parameters:
newMaximum - the new maximum value for this scroll bar.
See Also:
setValues, setMinimum
 o getVisibleAmount
 public int getVisibleAmount()
Gets the visible amount of this scroll bar.

The visible amount of a scroll bar is the range of values represented by the width of the scroll bar's bubble. It is used to determine the scroll bar's block increment.

Returns:
the visible amount of this scroll bar.
See Also:
setVisibleAmount
 o getVisible
 public int getVisible()
Note: getVisible() is deprecated. As of JDK version 1.1, replaced by getVisibleAmount().

 o setVisibleAmount
 public void setVisibleAmount(int newAmount)
Sets the visible amount of this scroll bar.

The visible amount of a scroll bar is the range of values represented by the width of the scroll bar's bubble. It is used to determine the scroll bar's block increment.

Normally, a program should change a scroll bar's value only by calling setValues. The setValues method simultaneously and synchronously sets the minimum, maximum, visible amount, and value properties of a scroll bar, so that they are mutually consistent.

Parameters:
newAmount - the amount visible per page.
See Also:
getVisibleAmount, setValues
 o setUnitIncrement
 public void setUnitIncrement(int v)
Sets the unit increment for this scroll bar.

The unit increment is the value that is added (subtracted) when the user activates the unit increment area of the scroll bar, generally through a mouse or keyboard gesture that the scroll bar receives as an adjustment event.

Parameters:
v - the amount by which to increment or decrement the scroll bar's value.
See Also:
getUnitIncrement
 o setLineIncrement
 public synchronized void setLineIncrement(int v)
Note: setLineIncrement() is deprecated. As of JDK version 1.1, replaced by setUnitIncrement(int).

 o getUnitIncrement
 public int getUnitIncrement()
Gets the unit increment for this scrollbar.

The unit increment is the value that is added (subtracted) when the user activates the unit increment area of the scroll bar, generally through a mouse or keyboard gesture that the scroll bar receives as an adjustment event.

Returns:
the unit increment of this scroll bar.
See Also:
setUnitIncrement
 o getLineIncrement
 public int getLineIncrement()
Note: getLineIncrement() is deprecated. As of JDK version 1.1, replaced by getUnitIncrement().

 o setBlockIncrement
 public void setBlockIncrement(int v)
Sets the block increment for this scroll bar.

The block increment is the value that is added (subtracted) when the user activates the block increment area of the scroll bar, generally through a mouse or keyboard gesture that the scroll bar receives as an adjustment event.

Parameters:
v - the amount by which to increment or decrement the scroll bar's value.
See Also:
getBlockIncrement
 o setPageIncrement
 public synchronized void setPageIncrement(int v)
Note: setPageIncrement() is deprecated. As of JDK version 1.1, replaced by setBlockIncrement().

 o getBlockIncrement
 public int getBlockIncrement()
Gets the block increment of this scroll bar.

The block increment is the value that is added (subtracted) when the user activates the block increment area of the scroll bar, generally through a mouse or keyboard gesture that the scroll bar receives as an adjustment event.

Returns:
the block increment of this scroll bar.
See Also:
setBlockIncrement
 o getPageIncrement
 public int getPageIncrement()
Note: getPageIncrement() is deprecated. As of JDK version 1.1, replaced by getBlockIncrement().

 o setValues
 public synchronized void setValues(int value,
                                    int visible,
                                    int minimum,
                                    int maximum)
Sets the values of four properties for this scroll bar.

This method simultaneously and synchronously sets the values of four scroll bar properties, assuring that the values of these properties are mutually consistent. It enforces the constraints that maximum cannot be less than minimum, and that value cannot be less than the minimum or greater than the maximum.

Parameters:
value - is the position in the current window.
visible - is the amount visible per page.
minimum - is the minimum value of the scroll bar.
maximum - is the maximum value of the scroll bar.
 o addAdjustmentListener
 public synchronized void addAdjustmentListener(AdjustmentListener l)
Adds the specified adjustment listener to receive instances of AdjustmentEvent from this scroll bar.

Parameters:
l - the adjustment listener.
See Also:
AdjustmentEvent, AdjustmentListener, removeAdjustmentListener
 o removeAdjustmentListener
 public synchronized void removeAdjustmentListener(AdjustmentListener l)
Removes the specified adjustment listener so that it no longer receives instances of AdjustmentEvent from this scroll bar.

Parameters:
l - the adjustment listener.
See Also:
AdjustmentEvent, AdjustmentListener, addAdjustmentListener
 o processEvent
 protected void processEvent(AWTEvent e)
Processes events on this scroll bar. If the event is an instance of AdjustmentEvent, it invokes the processAdjustmentEvent method. Otherwise, it invokes its superclass's processEvent method.

Parameters:
e - the event.
Overrides:
processEvent in class Component
See Also:
AdjustmentEvent, processAdjustmentEvent
 o processAdjustmentEvent
 protected void processAdjustmentEvent(AdjustmentEvent e)
Processes adjustment events occurring on this scrollbar by dispatching them to any registered AdjustmentListener objects.

This method is not called unless adjustment events are enabled for this component. Adjustment events are enabled when one of the following occurs:

  • An AdjustmentListener object is registered via addAdjustmentListener.
  • Adjustment events are enabled via enableEvents.

Parameters:
e - the adjustment event.
See Also:
AdjustmentEvent, AdjustmentListener, addAdjustmentListener, enableEvents
 o paramString
 protected String paramString()
Returns the parameter string representing the state of this scroll bar. This string is useful for debugging.

Returns:
the parameter string of this scroll bar.
Overrides:
paramString in class Component

All Packages  Class Hierarchy  This Package  Previous  Next  Index

Submit a bug or feature - Version 1.1.8 of Java Platform API Specification
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1995-1999 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.