Previous | Next | Trail Map | To 1.1 -- And Beyond! | GUI Changes: The AWT Grows Up


Writing an Adjustment Listener

Adjustment events notify you of changes in the value of components that implement the Adjustable(in the API reference documentation) interface. Adjustable objects have an integer value, and they generate adjustment events whenever that value changes.

In addition to the Scrollbar class,(in the Creating a User Interface trail), which directly implements Adjustable, the ScrollPane(in the API reference documentation) class's vertical and horizontal scrollbars implement Adjustable. If you want to peek at adjustment events within a scroll pane, you can get the necessary Adjustable objects using the getVAdjustable and getHAdjustable methods.

There are five kinds of adjustment events: [CHECK ALL THESE]

track
The user explicitly adjusted the value of the component. For a scrollbar, this might be the result of the user dragging the scrollbar knob.

unit increment
unit decrement
The user indicated the wish to slightly adjust the value of the component. For a scrollbar, this might be the result of the user clicking once on an up arrow or down arrow.

block increment
block decrement
The user indicated the wish to adjust the value of the component by a larger amount. For scrollbar, this might be the result of the user clicking once just above the down arrow or just below the up arrow.

Adjustment Event Methods

The AdjustmentListener(in the API reference documentation) interface has just one method, so it has no corresponding adapter class. Here's the method:
void adjustmentValueChanged(AdjustmentEvent)
Called by the AWT just after the listened-to component's value changes.

Examples of Handling Adjustment Events

The following applet demonstrates item events. [describe applet]

[applet goes here]


Try this:
  1. Do something.

You can find the applet's code [nowhere yet]. Here is the applet's item event handling code:

[code goes here]

You can find more examples of item listeners in the following sections: [LIST GOES HERE]

The AdjustmentEvent Class

Each item event method has a single parameter: an AdjustmentEvent(in the API reference documentation) object. The AdjustmentEvent class defines the following handy methods:
Adjustable getAdjustable()
Returns the component the generated the event.
int getAdjustmentType()
Returns the type of adjustment that occurred. The returned value is one of the following constants defined in the AdjustmentEvent class: UNIT_INCREMENT, UNIT_DECREMENT, BLOCK_INCREMENT, BLOCK_DECREMENT, TRACK.
int getValue()
Returns the value of the component just after the adjustment occurred.


Previous | Next | Trail Map | To 1.1 -- And Beyond! | GUI Changes: The AWT Grows Up