Java Reference
In-Depth Information
DefaultBoundedRangeModel
has two constructors:
public DefaultBoundedRangeModel()
public DefaultBoundedRangeModel(int value, int extent, int minimum, int maximum)
The no-argument version sets up the
minimum
,
value
, and
extent
properties of the model
to have a setting of 0. The remaining
maximum
property gets a setting of 100.
The second constructor version takes four integer parameters, explicitly setting four proper-
ties. For both constructors, the initial value of the
valuelsAdjusting
property is
false
because
the value of the model isn't yet changing beyond the initial value.
■
Note
Unless you're sharing a model across multiple components, it generally isn't necessary to create a
BoundedRangeModel
. Even if you're sharing a model across multiple components, you can create just the
first component and get its
BoundedRangeModel
model to share.
As with practically all of the classes that manage their own listener lists, you can ask
DefaultBoundedRangeModel
for the listeners assigned to it. Here, you ask the model for its
ChangeListener
list with
getListeners(ChangeListener.class)
. This returns an array of
EventListener
objects.
JScrollBar Class
The simplest of the bounded range components is the
JScrollBar
. The
JScrollBar
component
is used within the
JScrollPane
container, described in Chapter 11, to control the scrollable
region. You can also use this component within your own containers, although with the flexibility
of
JScrollPane
this typically isn't necessary. The one point to remember about
JScrollBar
,
however, is that it isn't used for the entry of a value, but solely for the scrolling of a region of
screen real estate. For the entry of a value, you use the
JSlider
component discussed in the
next section.
■
Note
The
JScrollBar
within a
JScrollPane
is actually a specialized subclass of
JScrollBar
that
properly deals with scrollable components that implement the
Scrollable
interface. Although you can
change the scrollbars of a
JScrollPane
, it's usually unnecessary—and more work than you might think.
As Figure 12-2 shows, the horizontal
JScrollBar
is composed of several parts. Starting
from the middle and working outward, you find the scrollbar's
thumb
—also called a
knob
or
slider
. The width of the thumb is the
extent
property from the
BoundedRangeModel
. The current
value of the scrollbar is at the left edge of the thumb. To the immediate left and right of the
thumb are the block paging areas. Clicking to the left of the thumb will decrement the scrollbar's
value, while clicking to the right increments it. The increased or decreased amount of the
scrollbar's value is the scrollbar's
blockIncrement
property.