java.lang.Objectjava.awt.Component
java.awt.Scrollbar
All Implemented Interfaces:
Accessible, Adjustable, MenuContainer, Serializable, ImageObserver
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" (also called the "thumb" or "scroll box") can be used to 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 in this example is the visible amount. The horizontal scroll bar in this example could be created with code like the following:
ranger = new Scrollbar(Scrollbar.HORIZONTAL, 0, 60, 0, 300); add(ranger);
Note that the actual maximum value of the scroll bar is the
maximum minus the visible amount.
In the previous example, because the maximum is
300 and the visible amount is 60, the actual maximum
value is 240. The range of the scrollbar track is 0 - 300.
The left side of the bubble indicates the value of the
scroll bar.
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:
AdjustmentEvent.TRACK is sent out when the
user drags the scroll bar's bubble.
AdjustmentEvent.UNIT_INCREMENT is sent out
when the user clicks in the left arrow of a horizontal scroll
bar, or the top arrow of a vertical scroll bar, or makes the
equivalent gesture from the keyboard.
AdjustmentEvent.UNIT_DECREMENT is sent out
when the user clicks in the right arrow of a horizontal scroll
bar, or the bottom arrow of a vertical scroll bar, or makes the
equivalent gesture from the keyboard.
AdjustmentEvent.BLOCK_INCREMENT is sent out
when the user clicks in the track, to the left of the bubble
on a horizontal scroll bar, or above the bubble on a vertical
scroll bar. By convention, the Page Up
key is equivalent, if the user is using a keyboard that
defines a Page Up key.
AdjustmentEvent.BLOCK_DECREMENT is sent out
when the user clicks in the track, to the right of the bubble
on a horizontal scroll bar, or below the bubble on a vertical
scroll bar. By convention, the Page Down
key is equivalent, if the user is using a keyboard that
defines a Page Down key.
The JDK 1.0 event system is supported for backwards compatibility, but its use with newer versions of the platform is discouraged. The five types of adjustment events introduced with JDK 1.1 correspond to the five event types that are associated with scroll bars in previous platform versions. The following list gives the adjustment event type, and the corresponding JDK 1.0 event type it replaces.
AdjustmentEvent.TRACK replaces
Event.SCROLL_ABSOLUTE
AdjustmentEvent.UNIT_INCREMENT replaces
Event.SCROLL_LINE_UP
AdjustmentEvent.UNIT_DECREMENT replaces
Event.SCROLL_LINE_DOWN
AdjustmentEvent.BLOCK_INCREMENT replaces
Event.SCROLL_PAGE_UP
AdjustmentEvent.BLOCK_DECREMENT replaces
Event.SCROLL_PAGE_DOWN
Note: We recommend using a Scrollbar
for value selection only. If you want to implement
a scrollable component inside a container, we recommend you use
a ScrollPane . If you use a
Scrollbar for this purpose, you are likely to
encounter issues with painting, key handling, sizing and
positioning.
Sami - ShaioJDK1.0 - | Nested Class Summary: | ||
|---|---|---|
| protected class | Scrollbar.AccessibleAWTScrollBar | This class implements accessibility support for the
Scrollbar class. It provides an implementation of
the Java Accessibility API appropriate to scrollbar
user-interface elements. |
| Field Summary | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| public static final int | HORIZONTAL | A constant that indicates a horizontal scroll bar. | ||||||||||||||||||||||
| public static final int | VERTICAL | A constant that indicates a vertical scroll bar. | ||||||||||||||||||||||
| int | value | The value of the Scrollbar.
This property must be greater than or equal to minimum
and less than or equal to
maximum - visibleAmount | ||||||||||||||||||||||
| int | maximum | The maximum value of the Scrollbar.
This value must be greater than the minimum
value.
| ||||||||||||||||||||||
| int | minimum | The minimum value of the Scrollbar.
This value must be less than the maximum
value.
| ||||||||||||||||||||||
| int | visibleAmount | The size of the Scrollbar's bubble.
When a scroll bar is used to select a range of values,
the visibleAmount represents the size of this range.
This is visually indicated by the size of the bubble.
| ||||||||||||||||||||||
| int | orientation | The Scrollbar's orientation--being either horizontal
or vertical.
This value should be specified when the scrollbar is created.orientation can be either : VERTICAL or
HORIZONTAL only.
| ||||||||||||||||||||||
| int | lineIncrement | The amount by which the scrollbar value will change when going
up or down by a line.
This value must be greater than zero.
| ||||||||||||||||||||||
| int | pageIncrement | The amount by which the scrollbar value will change when going
up or down by a page.
This value must be greater than zero.
| ||||||||||||||||||||||
| transient boolean | isAdjusting | The adjusting status of the Scrollbar.
True if the value is in the process of changing as a result of
actions being taken by the user.
| ||||||||||||||||||||||
| transient AdjustmentListener | adjustmentListener | |||||||||||||||||||||||
| Constructor: | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||||||
The
| ||||||||||||||||||||||||
The The parameters supplied to this constructor are subject to the constraints described in #setValues(int, int, int, int) .
|
| Methods from java.lang.Object: |
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method from java.awt.Scrollbar Detail: |
|---|
AdjustmentEvent from this scroll bar.
If l is null, no exception is thrown and no
action is performed.
Refer to AWT Threading Issues for details on AWT's threading model. |
Scrollbar's peer. The peer allows you to modify
the appearance of the Scrollbar without changing any of its
functionality. |
getName
when the name is null. |
|
AccessibleContext associated with this
Scrollbar. For scrollbars, the
AccessibleContext takes the form of an
AccessibleAWTScrollBar. A new
AccessibleAWTScrollBar instance is created if necessary. |
|
The block increment is the value that is added or 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. The block increment must be greater than zero. |
Deprecated! As - of JDK version 1.1,
replaced by getUnitIncrement(). |
FooListeners
upon this Scrollbar.
FooListeners are registered using the
addFooListener method.
You can specify the MouseListener[] mls = (MouseListener[])(c.getListeners(MouseListener.class));If no such listeners exist, this method returns an empty array. |
|
|
|
Deprecated! As - of JDK version 1.1,
replaced by getBlockIncrement(). |
The unit increment is the value that is added or 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. The unit increment must be greater than zero. |
|
|
Deprecated! As - of JDK version 1.1,
replaced by getVisibleAmount(). |
When a scroll bar is used to select a range of values, the visible amount is used to represent the range of values that are currently visible. The size of the scroll bar's bubble (also called a thumb or scroll box), usually gives a visual representation of the relationship of the visible amount to the range of the scroll bar.
The scroll bar's bubble may not be displayed when it is not
moveable (e.g. when it takes up the entire length of the
scroll bar's track, or when the scroll bar is disabled).
Whether the bubble is displayed or not will not affect
the value returned by |
Scrollbar.
This method is intended to be used only for debugging purposes, and the
content and format of the returned string may vary between
implementations. The returned string may be empty but may not be
null. |
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:
Note that if the event parameter is |
AdjustmentEvent, it invokes the
processAdjustmentEvent method.
Otherwise, it invokes its superclass's
processEvent method.
Note that if the event parameter is |
AdjustmentEvent from this scroll bar.
If l is null, no exception is thrown and no action
is performed.
Refer to AWT Threading Issues for details on AWT's threading model. |
The block increment is the value that is added or 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. The block increment must be greater than zero. Attepts to set the block increment to a value lower than 1 will result in a value of 1 being set. |
Deprecated! As - of JDK version 1.1,
replaced by setUnitIncrement(int). |
When
Normally, a program should change a scroll bar's maximum
value only by calling
Note that setting the maximum value to |
When
Normally, a program should change a scroll bar's minimum
value only by calling
Note that setting the minimum value to |
|
Deprecated! As - of JDK version 1.1,
replaced by setBlockIncrement(). |
The unit increment is the value that is added or 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. The unit increment must be greater than zero. Attepts to set the unit increment to a value lower than 1 will result in a value of 1 being set. |
If the value supplied is less than the current
Normally, a program should change a scroll bar's
value only by calling
Calling this method does not fire an
|
valueIsAdjusting property. |
value, visibleAmount,
minimum, and maximum.
If the values supplied for these properties are inconsistent
or incorrect, they will be changed to ensure consistency.
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
following constraints:
Calling this method does not fire an
|
When a scroll bar is used to select a range of values, the visible amount is used to represent the range of values that are currently visible. The size of the scroll bar's bubble (also called a thumb or scroll box), usually gives a visual representation of the relationship of the visible amount to the range of the scroll bar.
The scroll bar's bubble may not be displayed when it is not
moveable (e.g. when it takes up the entire length of the
scroll bar's track, or when the scroll bar is disabled).
Whether the bubble is displayed or not will not affect
the value returned by
If the visible amount supplied is less than
Normally, a program should change a scroll bar's
value only by calling |