img
Here, newValue specifies the new value for the scroll bar. When you set a value, the slider
box inside the scroll bar will be positioned to reflect the new value.
You can also retrieve the minimum and maximum values via getMinimum( ) and
getMaximum( ), shown here:
int getMinimum( )
int getMaximum( )
They return the requested quantity.
By default, 1 is the increment added to or subtracted from the scroll bar each time it is
scrolled up or down one line. You can change this increment by calling setUnitIncrement( ).
By default, page-up and page-down increments are 10. You can change this value by calling
setBlockIncrement( ). These methods are shown here:
void setUnitIncrement(int newIncr)
void setBlockIncrement(int newIncr)
Handling Scroll Bars
To process scroll bar events, you need to implement the AdjustmentListener interface.
Each time a user interacts with a scroll bar, an AdjustmentEvent object is generated. Its
getAdjustmentType( ) method can be used to determine the type of the adjustment. The
types of adjustment events are as follows:
BLOCK_DECREMENT
A page-down event has been generated.
BLOCK_INCREMENT
A page-up event has been generated.
TRACK
An absolute tracking event has been generated.
UNIT_DECREMENT
The line-down button in a scroll bar has been pressed.
UNIT_INCREMENT
The line-up button in a scroll bar has been pressed.
The following example creates both a vertical and a horizontal scroll bar. The current
settings of the scroll bars are displayed. If you drag the mouse while inside the window, the
coordinates of each drag event are used to update the scroll bars. An asterisk is displayed at
the current drag position.
// Demonstrate scroll bars.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="SBDemo" width=300 height=200>
</applet>
*/
public class SBDemo extends Applet
implements AdjustmentListener, MouseMotionListener {
String msg = "";
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home