Java Reference
In-Depth Information
Figure 12-2. Horizontal JScrollBar anatomy
On the left and right edges of the scrollbar are arrow buttons. When the left arrow is pressed,
the scrollbar decrements down a unit. The scrollbar's unitIncrement property specifies this
unit. Typically, this value is one, though it doesn't have to be. To the immediate right of the left
arrow is the minimum value of the scrollbar and the model. In addition to decreasing the value
with the left arrow, clicking the right arrow causes the scrollbar to increment a unit. To the
immediate left of the right arrow is the scrollbar's maximum range. The maximum value is
actually a little farther to the left, where this “little farther” is specified by the model's extent
property. When the thumb is next to the right arrow, this places the scrollbar value of the
scrollbar at the left edge of the thumb, which is the case with all other positions, no matter
where the thumb is.
A vertical JScrollBar is composed of the same parts as a horizontal JScrollBar , with the
minimum and decrement parts at the top, and the value designated by the top edge of the
scrollbar's thumb. The maximum and increment parts are at the bottom.
As previously mentioned, the model for the JScrollBar is the BoundedRangeModel . The
delegate for the user interface is the ScrollBarUI .
Now that you've seen the different pieces of a JScrollBar , let's see how to use them.
Creating JScrollBar Components
There are three constructors for JScrollBar :
public JScrollBar()
JScrollBar aJScrollBar = new JScrollBar();
public JScrollBar(int orientation)
// Vertical
JScrollBar aJScrollBar = new JScrollBar(JScrollBar.VERTICAL);
// Horizontal
JScrollBar bJScrollBar = new JScrollBar(JScrollBar.HORIZONTAL);
public JScrollBar(int orientation, int value, int extent, int minimum, int maximum)
// Horizontal, initial value 500, range 0-1000, and extent of 25
JScrollBar aJScrollBar = new JScrollBar(JScrollBar.HORIZONTAL, 500, 25, 0, 1025);
Creating a JScrollBar with no arguments creates a vertical scrollbar with a default data
model. The model has an initial value of 0, a minimum of 0, a maximum of 100, and an extent
Search WWH ::




Custom Search