javax.swing
Class JProgressBarjava.lang.Object | +--java.awt.Component | +--java.awt.Container | +--javax.swing.JComponent | +--javax.swing.JProgressBar
- All Implemented Interfaces:
- Accessible, ImageObserver, MenuContainer, Serializable, SwingConstants
- public class JProgressBar
- extends JComponent
- implements SwingConstants, 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.
- See Also:
- BasicProgressBarUI
Nested Class Summary
protected class JProgressBar.AccessibleJProgressBar
This class implements accessibility support for the JProgressBar class.
Nested classes inherited from class javax.swing.JComponent
Nested classes inherited from class java.awt.Container
Nested classes inherited from class java.awt.Component Component.BltBufferStrategy, Component.FlipBufferStrategy
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, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields inherited from class java.awt.Component BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface javax.swing.SwingConstants BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH,