Java Reference
In-Depth Information
public JProgressBar(int orientation, int minimum, int maximum)
JProgressBar aJProgressBar = new JProgressBar(JProgressBar.VERTICAL, 0, 1000);
public JProgressBar(BoundedRangeModel model)
// Data model, initial value 0, range 0-250, and extent of 0
DefaultBoundedRangeModel model = new DefaultBoundedRangeModel(0, 0, 0, 250);
JProgressBar aJProgressBar = new JProgressBar(model);
Creating a
JProgressBar
with no arguments results in a horizontal progress bar with a
default data model. The model has an initial value of 0, a minimum value of 0, a maximum
value of 100, and an extent of 0. The progress bar has an extent, but it doesn't use it, even
though it's part of the data model.
You can explicitly set the orientation with
JProgressBar.HORIZONTAL
or
JProgressBar.VERTICAL
, as well as any of the specific model properties, with the different
constructors. In addition, you can explicitly set the data model for the component.
■
Caution
Initializing the orientation to a value not equivalent to
VERTICAL
or
HORIZONTAL
throws an
IllegalArgumentException
.
Creating a
JProgressBar
from a
BoundedRangeModel
is a little awkward in the sense that the
progress bar virtually ignores one setting and the initial value is normally initialized to the
minimum. Assuming you want the
JProgressBar
to start as a user might expect it to, you need
to remember to set the extent to 0 and the value to the minimum when creating the model. If
you increase the
extent
property, the maximum setting of the
value
property is decreased by
that amount, and the
value
setting will never reach the setting of the
maximum
property.
JProgressBar Properties
After you've created a
JProgressBar
, you may want to modify it. Table 12-5 shows the 14 properties
of
JProgressBar
.
Table 12-5.
JProgressBar Properties
Property Name
Data Type
Access
accessibleContext
AccessibleContext
Read-only
borderPainted
boolean
Read-write bound
changeListeners
ChangeListener[ ]
Read-only
indeterminate
boolean
Read-write bound
maximum
int
Read-write
minimum
int
Read-write
model
BoundedRangeModel
Read-write
orientation
int
Read-write bound