javax.swing
public class JProgressBar extends JComponent implements SwingConstants, Accessible
JProgressBar
fills a percentage of its bar based on its
current value. In indeterminate mode, it creates box and bounces it between
its bounds.
This component has the following properties:
Property | Stored in | Bound? |
---|---|---|
borderPainted | progressBar | yes |
changeListeners | progressBar | no |
indeterminate | progressBar | yes |
maximum | model | no |
minimum | model | no |
model | progressBar | no |
orientation | progressBar | yes |
percentComplete | progressBar | no |
string | progressBar | yes |
stringPainted | progressBar | yes |
value | model | no |
Nested Class Summary | |
---|---|
protected class | JProgressBar.AccessibleJProgressBar
Provides the accessibility features for the JProgressBar
component. |
Field Summary | |
---|---|
protected ChangeEvent | changeEvent
A single change event reused for all events. |
protected ChangeListener | changeListener
The listener that is registered with the model. |
protected BoundedRangeModel | model
The model defining the bounds and current value for the progress bar. |
protected int | orientation |
protected boolean | paintBorder
A flag the controls whether or not the component's border is painted.
|
protected boolean | paintString
A flag that controls whether a string is displayed within the progress
bar. |
protected String | progressString
A custom string for display in the progress bar. |
Constructor Summary | |
---|---|
JProgressBar()
Creates a new JProgressBar with default attributes. | |
JProgressBar(int orientation)
Creates a new JProgressBar with the specified
orientation . | |
JProgressBar(int minimum, int maximum)
Creates a new JProgressBar with the specified value range.
| |
JProgressBar(int orientation, int minimum, int maximum)
Creates a new JProgressBar with the specified range and
orientation. | |
JProgressBar(BoundedRangeModel model)
Creates a new JProgressBar with the specified model. |
Method Summary | |
---|---|
void | addChangeListener(ChangeListener listener)
Registers a listener with this component so that it will receive
notification of component state changes.
|
protected ChangeListener | createChangeListener()
Creates a new ChangeListener that calls
fireStateChanged whenever it receives a ChangeEvent
(typically from the component's model ). |
protected void | fireStateChanged()
Sends a ChangeEvent to all registered listeners to indicate that
the state of the JProgressBar has changed.
|
AccessibleContext | getAccessibleContext()
Returns the object that provides accessibility features for this
JProgressBar component.
|
ChangeListener[] | getChangeListeners()
Returns an array of the listeners that are registered with this component.
|
int | getMaximum()
Returns the maximum value for the JProgressBar . |
int | getMinimum()
Returns the minimum value for the JProgressBar . |
BoundedRangeModel | getModel()
Returns the model for the JProgressBar .
|
int | getOrientation() |
double | getPercentComplete()
Returns the current value expressed as a percentage. |
String | getString() |
ProgressBarUI | getUI()
Returns the UI delegate for this JProgressBar .
|
String | getUIClassID()
Returns the suffix ( "ProgressBarUI" in this case) used to
determine the class name for a UI delegate that can provide the look and
feel for a JProgressBar .
|
int | getValue()
Returns the current value for the JProgressBar . |
boolean | isBorderPainted()
Returns a flag that controls whether or not the component's border is
painted. |
boolean | isIndeterminate()
Returns a flag that indicates the mode for this JProgressBar
(true for indeterminate mode, and false for
determinate mode).
|
boolean | isStringPainted()
Returns the flag that controls whether or not the string returned by
getString is displayed by the JProgressBar
component.
|
protected void | paintBorder(Graphics graphics)
Paints the component's border, but only if isBorderPainted
returns true .
|
protected String | paramString()
Returns an implementation-dependent string describing the attributes of
this JProgressBar .
|
void | removeChangeListener(ChangeListener listener)
Deregisters a listener so that it no longer receives notification of
component state changes.
|
void | setBorderPainted(boolean painted)
Sets the flag that controls whether or not the component's border is
painted. |
void | setIndeterminate(boolean flag)
Sets the flag that controls the mode for this JProgressBar
(true for indeterminate mode, and false for
determinate mode). |
void | setMaximum(int maximum)
Sets the maximum value for the JProgressBar . |
void | setMinimum(int minimum)
Sets the minimum value for the JProgressBar . |
void | setModel(BoundedRangeModel model)
Sets the model for the JProgressBar and sends a
ChangeEvent to all registered listeners.
|
void | setOrientation(int orientation)
Sets the orientation for this JProgressBar component and,
if the value changes, sends a PropertyChangeEvent (with the
property name "orientation" ) to all registered listeners.
|
void | setString(String string)
Sets the string to display within the progress bar and, if the new value
is different to the old value, sends a PropertyChangeEvent (with
the property name "string" ) to all registered listeners. |
void | setStringPainted(boolean painted)
Sets the flag that controls whether or not the string returned by
getString is displayed by the JProgressBar
component. |
void | setUI(ProgressBarUI ui)
Sets the UI delegate for this component.
|
void | setValue(int value)
Sets the current value for the JProgressBar . |
void | updateUI()
Sets this JProgressBar 's UI delegate to the default
(obtained from the UIManager) for the current look and feel. |
See Also: fireStateChanged
See Also: setModel
JProgressBar
(HORIZONTAL or VERTICAL).
Defaults to HORIZONTAL.See Also: JProgressBar
true
.See Also: JProgressBar
See Also: JProgressBar
null
, a default string will be generated.See Also: setString
JProgressBar
with default attributes. The
following defaults are used:
value
: 0;minimum
: 0;maximum
: 100;orientation
: HORIZONTAL.JProgressBar
with the specified
orientation
. The following defaults are used:
value
: 0;minimum
: 0;maximum
: 100;Parameters: orientation the orientation (JProgressBar or JProgressBar).
Throws: IllegalArgumentException if orientation
is not one of
the specified values.
JProgressBar
with the specified value range.
The following defaults are used:
value
: minimum
;orientation
: HORIZONTAL.Parameters: minimum the lower bound of the value range. maximum the upper bound of the value range.
JProgressBar
with the specified range and
orientation. The following defaults are used:
value
: minimum
;Parameters: minimum the lower bound of the value range. maximum the upper bound of the value range. orientation the orientation (JProgressBar or JProgressBar).
Throws: IllegalArgumentException if orientation
is not one of
the specified values.
JProgressBar
with the specified model. The
following defaults are used:
orientation
: HORIZONTAL.Parameters: model the model (null
not permitted).
Parameters: listener the listener.
See Also: removeChangeListener
model
). This listener is
registered with the progress bar's model, so that changes made to the
model directly will automatically result in the progress bar's listeners
being notified also.
Returns: A new listener.
JProgressBar
has changed.
See Also: createChangeListener
JProgressBar
component.
Returns: The accessible context (an instance of AccessibleJProgressBar).
null
.
Returns: An array of listeners.
Since: 1.4
JProgressBar
. This defines
the upper bound for the current value, and is stored in the component's
model
.
Returns: The maximum value.
See Also: JProgressBar
JProgressBar
. This defines
the lower bound for the current value, and is stored in the component's
model
.
Returns: The minimum value.
See Also: JProgressBar
JProgressBar
component, which
is either HORIZONTAL or
VERTICAL. The default orientation is
HORIZONTAL
.
Returns: The orientation.
See Also: JProgressBar
(value - min) / (max - min)
.
Returns: The percentage (a value in the range 0.0 to 1.0).
JProgressBar
if
isStringPainted returns true
. If no string has
been explicitly set, this method will return a string displaying the
value of getPercentComplete.
Returns: The string.
See Also: setString JProgressBar
JProgressBar
.
Returns: The UI delegate.
"ProgressBarUI"
in this case) used to
determine the class name for a UI delegate that can provide the look and
feel for a JProgressBar
.
Returns: "ProgressBarUI"
.
JProgressBar
. This value
is fetched from the model.
Returns: The current value.
See Also: JProgressBar
true
.
Returns: true
if the component's border should be painted,
and false
otherwise.
See Also: JProgressBar
JProgressBar
(true
for indeterminate mode, and false
for
determinate mode).
Returns: A flag indicating the mode for the JProgressBar
.
Since: 1.4
See Also: JProgressBar
JProgressBar
component.
Returns: true
if the string should be displayed, and
false
otherwise.
See Also: JProgressBar
true
.
Parameters: graphics the graphics object to paint with.
See Also: JProgressBar
JProgressBar
.
Returns: A string describing the attributes of this
JProgressBar
(never null
).
Parameters: listener the listener.
See Also: addChangeListener
Parameters: painted the new flag value.
See Also: isBorderPainted paintBorder
JProgressBar
(true
for indeterminate mode, and false
for
determinate mode). If the flag value changes, this method sends a
PropertyChangeEvent (with the property name
"indeterminate"
) to all registered listeners.
If the JProgressBar
is determinate, it paints a percentage
of the bar described by its value. If it is indeterminate, it simply
bounces a box between the ends of the bar; the value of the
JProgressBar
is ignored.
Parameters: flag the new flag value.
Since: 1.4
See Also: isIndeterminate
JProgressBar
. The value is
stored in the component's model
(see getModel).
If the new value is different to the old value, a ChangeEvent is
sent to the model's registered listeners. In turn, this triggers a call
to fireStateChanged which will send a ChangeEvent
to this component's registered listeners.
Parameters: maximum the maximum value.
See Also: getMaximum
JProgressBar
. The value is
stored in the component's model
(see getModel).
If the new value is different to the old value, a ChangeEvent is
sent to the model's registered listeners. In turn, this triggers a call
to fireStateChanged which will send a ChangeEvent
to this component's registered listeners.
Parameters: minimum the minimum value.
See Also: getMinimum
JProgressBar
and sends a
ChangeEvent to all registered listeners.
Parameters: model the model (null
not permitted).
See Also: getModel
JProgressBar
component and,
if the value changes, sends a PropertyChangeEvent (with the
property name "orientation"
) to all registered listeners.
Parameters: orientation the orientation (JProgressBar or JProgressBar).
Throws: IllegalArgumentException if orientation
is not
one of the listed values.
See Also: getOrientation
"string"
) to all registered listeners. If
the string is set to null
, getString will return
a default string.
Parameters: string the string (null
permitted).
See Also: getString JProgressBar
JProgressBar
component. If the flag value changes, a PropertyChangeEvent (with
the property name "stringPainted"
) is sent to all registered
listeners.
Parameters: painted the new flag value.
See Also: isStringPainted setString
Parameters: ui the new UI delegate.
JProgressBar
. The value is
stored in the component's model
(see getModel).
If the new value is different to the old value, a ChangeEvent is
sent to the model's registered listeners. In turn, this triggers a call
to fireStateChanged which will send a ChangeEvent
to this component's registered listeners.
If value
is outside the range minimum
to
maximum
, it will be set to the nearest of those boundary
values.
Parameters: value the new value.
See Also: getValue
JProgressBar
's UI delegate to the default
(obtained from the UIManager) for the current look and feel.