Java Reference
In-Depth Information
CHAPTER 12
■ ■ ■
Bounded Range Components
I
n the previous chapter, you saw how
JScrollPane
provides a scrollable region for those situations
when there isn't sufficient space to display an entire component on screen. Swing also offers
several components that support some type of scrolling or the display of a bounded range of values.
The available components are
JScrollBar
,
JSlider
,
JProgressBar
, and, in a more limited sense,
JTextField
. These components share a
BoundedRangeModel
as their data model. The default imple-
mentation of this data model provided with the Swing classes is the
DefaultBoundedRangeModel
class.
In this chapter, you'll look at the similarities and differences between these Swing
components. Let's start with their shared data model, the
BoundedRangeModel
.
BoundedRangeModel Interface
The
BoundedRangeModel
interface is the Model-View-Controller (MVC) data model shared by
the components described in this chapter. The interface contains four interrelated properties
that are necessary to describe a range of values:
minimum
,
maximum
,
value
, and
extent
.
The
minimum
and
maximum
properties define the limits of the value of the model. The
value
property defines what you might think of as the current setting of the model, where the maximum
setting of the
value
property is not necessarily the value of the
maximum
property of the model.
Instead, the maximum setting that the
value
property can take is the
maximum
property less the
extent
property. To help you visualize these properties, Figure 12-1 shows these settings in relation
to a
JScrollBar
. Any other purpose of the
extent
property depends on the component acting
as the model's view.
Figure 12-1.
BoundedRange properties on a JScrollBar
419