java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JProgressBar
All Implemented Interfaces:
SwingConstants, Accessible, HasGetTransferHandler, Serializable, MenuContainer, ImageObserver
{@code JProgressBar} uses a {@code BoundedRangeModel} as its data model, with the {@code value} property representing the "current" state of the task, and the {@code minimum} and {@code maximum} properties representing the beginning and end points, respectively.
To indicate that a task of unknown length is executing, you can put a progress bar into indeterminate mode. While the bar is in indeterminate mode, it animates constantly to show that work is occurring. As soon as you can determine the task's length and amount of progress, you should update the progress bar's value and switch it back to determinate mode.
Here is an example of creating a progress bar,
where task
is an object (representing some piece of work)
which returns information about the progress of the task:
progressBar = new JProgressBar(0, task.getLengthOfTask()); progressBar.setValue(0); progressBar.setStringPainted(true);Here is an example of querying the current state of the task, and using the returned value to update the progress bar:
progressBar.setValue(task.getCurrent());Here is an example of putting a progress bar into indeterminate mode, and then switching back to determinate mode once the length of the task is known:
progressBar = new JProgressBar(); ...//when the task of (initially) unknown length begins: progressBar.setIndeterminate(true); ...//do some work; get length of task... progressBar.setMaximum(newLength); progressBar.setValue(newValue); progressBar.setIndeterminate(false);
For complete examples and further documentation see How to Monitor Progress, a section in The Java Tutorial.
Warning: Swing is not thread safe. For more information see Swing's Threading Policy.
Warning:
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeansTM
has been added to the java.beans
package.
Please see java.beans.XMLEncoder .
attribute
- : isContainer false
description: A component that displays an integer value.Michael
- C. AlbersKathy
- WalrathNested Class Summary: | ||
---|---|---|
protected class | JProgressBar.AccessibleJProgressBar | This class implements accessibility support for the
JProgressBar class. It provides an implementation of the
Java Accessibility API appropriate to progress bar user-interface
elements.
Warning:
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeansTM
has been added to the |
Field Summary | ||
---|---|---|
protected int | orientation | Whether the progress bar is horizontal or vertical.
The default is HORIZONTAL .
|
protected boolean | paintBorder | Whether to display a border around the progress bar.
The default is true .
|
protected BoundedRangeModel | model | The object that holds the data for the progress bar.
|
protected String | progressString | An optional string that can be displayed on the progress bar.
The default is null . Setting this to a non-null
value does not imply that the string will be displayed.
To display the string, {@code paintString} must be {@code true}.
|
protected boolean | paintString | Whether to display a string of text on the progress bar.
The default is false .
Setting this to true causes a textual
display of the progress to be rendered on the progress bar. If
the progressString is null ,
the percentage of completion is displayed on the progress bar.
Otherwise, the progressString is
rendered on the progress bar.
|
protected transient ChangeEvent | changeEvent | Only one ChangeEvent is needed per instance since the
event's only interesting property is the immutable source, which
is the progress bar.
The event is lazily created the first time that an
event notification is fired.
|
protected ChangeListener | changeListener | Listens for change events sent by the progress bar's model,
redispatching them
to change-event listeners registered upon
this progress bar.
|
Constructor: |
---|
|
|
|
The
|
The
|
Method from javax.swing.JProgressBar Summary: |
---|
addChangeListener, createChangeListener, fireStateChanged, getAccessibleContext, getChangeListeners, getMaximum, getMinimum, getModel, getOrientation, getPercentComplete, getString, getUI, getUIClassID, getValue, isBorderPainted, isIndeterminate, isStringPainted, paintBorder, paramString, removeChangeListener, setBorderPainted, setIndeterminate, setMaximum, setMinimum, setModel, setOrientation, setString, setStringPainted, setUI, setValue, updateUI |
Methods from java.lang.Object: |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method from javax.swing.JProgressBar Detail: |
---|
ChangeListener to the progress bar. |
ChangeListener implementation.
The default {@code ChangeListener} simply calls the
{@code fireStateChanged} method to forward {@code ChangeEvent}s
to the {@code ChangeListener}s that have been added directly to the
progress bar. |
The event instance is created if necessary, and stored in {@code changeEvent}. |
AccessibleContext associated with this
JProgressBar . For progress bars, the
AccessibleContext takes the form of an
AccessibleJProgressBar .
A new AccessibleJProgressBar instance is created if necessary. |
ChangeListener s added
to this progress bar with addChangeListener . |
BoundedRangeModel . |
BoundedRangeModel . |
|
|
|
|
|
|
BoundedRangeModel .
The value is always between the
minimum and maximum values, inclusive. |
borderPainted property. |
indeterminate property. |
stringPainted property. |
borderPainted
property is true . |
JProgressBar .
This method is intended to be used only for debugging purposes. The
content and format of the returned string may vary between
implementations. The returned string may be empty but may not
be null . |
ChangeListener from the progress bar. |
borderPainted property, which is
true if the progress bar should paint its border.
The default value for this property is true .
Some look and feels might not implement painted borders;
they will ignore this property. |
indeterminate property of the progress bar,
which determines whether the progress bar is in determinate
or indeterminate mode.
An indeterminate progress bar continuously displays animation
indicating that an operation of unknown length is occurring.
By default, this property is false .
Some look and feels might not support indeterminate progress bars;
they will ignore this property.
See How to Monitor Progress for examples of using indeterminate progress bars. |
n .
The underlying If the maximum value is different from the previous maximum, all change listeners are notified. |
n .
The data model (a If the minimum value is different from the previous minimum, all change listeners are notified. |
JProgressBar .
Note that the {@code BoundedRangeModel}'s {@code extent} is not used,
and is set to {@code 0}. |
newOrientation ,
which must be {@code SwingConstants.VERTICAL} or
{@code SwingConstants.HORIZONTAL}. The default orientation
is {@code SwingConstants.HORIZONTAL}. |
null , implying the built-in behavior of
using a simple percent string.
If you have provided a custom progress string and want to revert to
the built-in behavior, set the string back to null .
The progress string is painted only if
the |
stringPainted property,
which determines whether the progress bar
should render a progress string.
The default is false , meaning
no string is painted.
Some look and feels might not support progress strings
or might support them only when the progress bar is in determinate mode. |
|
The data model (an instance of {@code BoundedRangeModel}) handles any mathematical issues arising from assigning faulty values. See the {@code BoundedRangeModel} documentation for details. If the new value is different from the previous value, all change listeners are notified. |
|