|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object![]()
![]()
![]()
java.awt.Component
![]()
![]()
![]()
java.awt.Container
![]()
![]()
![]()
javax.swing.JComponent
![]()
![]()
![]()
javax.swing.JProgressBar
, MenuContainer
, Serializable
, Accessible
, SwingConstants

public class JProgressBar

, Accessible

A component that, by default, displays an integer value within a bounded interval. A progress bar typically communicates the progress of some work by displaying its percentage of completion and possibly a textual display of this percentage.
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
that returns information about the progress of some work:
progressBar = new JProgressBar(0, task.getLengthOfTask()); progressBar.setValue(0); progressBar.setStringPainted(true);Here is an example of updating the value of 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:
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 XMLEncoder
.
BasicProgressBarUI
,
Serialized Form| Nested Class Summary | |
|---|---|
protected class |
JProgressBar.AccessibleJProgressBar
This class implements accessibility support for the JProgressBar class. |
Nested classes/interfaces inherited from class javax.swing.JComponent ![]() |
|---|
JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container ![]() |
|---|
Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component ![]() |
|---|
Component.AccessibleAWTComponent |
| Field Summary | |
|---|---|
protected 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. |
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. |
protected BoundedRangeModel |
model
The object that holds the data for the progress bar. |
protected int |
orientation
Whether the progress bar is horizontal or vertical. |
protected boolean |
paintBorder
Whether to display a border around the progress bar. |
protected boolean |
paintString
Whether to textually display a string on the progress bar. |
protected String |
progressString
An optional string that can be displayed on the progress bar. |
Fields inherited from class javax.swing.JComponent ![]() |
|---|
accessibleContext |
Fields inherited from class java.awt.Component ![]() |
|---|
BOTTOM_ALIGNMENT |
Fields inherited from interface javax.swing.SwingConstants ![]() |
|---|
BOTTOM |
Fields inherited from interface java.awt.image.ImageObserver ![]() |
|---|
ABORT |
| Constructor Summary | |
|---|---|
JProgressBar
Creates a horizontal progress bar that displays a border but no progress string. |
|
JProgressBar
Creates a horizontal progress bar that uses the specified model to hold the progress bar's data. |
|
JProgressBar
Creates a progress bar with the specified orientation, which can be either JProgressBar.VERTICAL or
JProgressBar.HORIZONTAL. |
|
JProgressBar
Creates a horizontal progress bar with the specified minimum and maximum. |
|
JProgressBar
Creates a progress bar using the specified orientation, minimum, and maximum. |
|
| Method Summary | |
|---|---|
void |
addChangeListener
Adds the specified ChangeListener to the progress bar. |
protected ChangeListener |
createChangeListener
Subclasses that want to handle change events from the model differently can override this to return an instance of a custom ChangeListener implementation. |
protected void |
fireStateChanged
Notifies all listeners that have registered interest in ChangeEvents. |
AccessibleContext |
getAccessibleContext
Gets the AccessibleContext associated with this
JProgressBar. |
ChangeListener |
getChangeListeners
Returns an array of all the ChangeListeners added
to this progress bar with addChangeListener. |
int |
getMaximum
Returns the progress bar's maximum value, which is stored in the progress bar's BoundedRangeModel. |
int |
getMinimum
Returns the progress bar's minimum value, which is stored in the progress bar's BoundedRangeModel. |
BoundedRangeModel |
getModel
Returns the data model used by this progress bar. |
int |
getOrientation
Returns JProgressBar.VERTICAL or
JProgressBar.HORIZONTAL, depending on the orientation
of the progress bar. |
double |
getPercentComplete
Returns the percent complete for the progress bar. |
String |
getString
Returns the current value of the progress string. |
ProgressBarUI |
getUI
Returns the look-and-feel object that renders this component. |
String |
getUIClassID
Returns the name of the look-and-feel class that renders this component. |
int |
getValue
Returns the progress bar's current value, which is stored in the progress bar's BoundedRangeModel. |
boolean |
isBorderPainted
Returns the borderPainted property. |
boolean |
isIndeterminate
Returns the value of the indeterminate property. |
boolean |
isStringPainted
Returns the value of the stringPainted property. |
protected void |
paintBorder
Paints the progress bar's border if the borderPainted
property is true. |
protected String |
paramString
Returns a string representation of this JProgressBar. |
void |
removeChangeListener
Removes a ChangeListener from the progress bar. |
void |
setBorderPainted
Sets the borderPainted property, which is
true if the progress bar should paint its border. |
void |
setIndeterminate
Sets the indeterminate property of the progress bar,
which determines whether the progress bar is in determinate
or indeterminate mode. |
void |
setMaximum
Sets the progress bar's maximum value (stored in the progress bar's data model) to n. |
void |
setMinimum
Sets the progress bar's minimum value (stored in the progress bar's data model) to n. |
void |
setModel
Sets the data model used by the JProgressBar. |
void |
setOrientation
Sets the progress bar's orientation to newOrientation,
which must be JProgressBar.VERTICAL or
JProgressBar.HORIZONTAL. |
void |
setString
Sets the value of the progress string. |
void |
setStringPainted
Sets the value of the stringPainted property,
which determines whether the progress bar
should render a progress string. |
void |
setUI
Sets the look-and-feel object that renders this component. |
void |
setValue
Sets the progress bar's current value (stored in the progress bar's data model) to n. |
void |
updateUI
Resets the UI property to a value from the current look and feel. |
Methods inherited from class javax.swing.JComponent ![]() |
|---|
addAncestorListener |