![]() ![]() |
![]() |
![]() ![]() ![]() ![]() |
![]() |
Applications that perform time-consuming tasks, such as downloading a file, often use progress bars to give feedback to the user about the progress of the task being performed. Swing implements progress bars as instantiations of a class named JProgressBar. This specification explains and illustrates how Swing implements uses the JProgressBar class to implement progress-bar components.
A progress bar is a bar-graph component that monitors a task as it is performed and indicates, in real time, how much of the task has been completed. Although a progress bar accepts no input from the user, the JProgressBar class used in Swing is pluggable-L&F component, so it is based on the model-view-controller (MVC) component framework described in the "Component Architecture" specification. Swing provides a default look and feel for JProgressBar objects, but because of the pluggable-L&F capabilities of Swing, you can design other looks if you prefer. By default, the progress-bar class used in Swing has an LED-style look similar to the one used in Windows NT and Windows 95.
Like JScrollbar, JProgressBar operates in both horizontal and vertical orientations. It also provides an optional border.
Because a progress bar is similar in many ways to both a slider and scroll bar (a progress bar can be thought of as a read-only range indicator, while a slider can be viewed as a read-write range manipulator) Swing's JProgressBar component uses the same model as the JSlider and JScrollbar classes: the BoundedRangeModel, which is described in the specification titled "The BoundedRangeModel API."
The JProgressBar class provides methods for manipulating the minimum, maximum, and value attributes of the BoundedRangeModel. JProgressBar ignores BoundedRangeModel's extent attribute. (It would have been possible to use the model's extent attribute, instead of its value attribute, to specify the percentage of completion of the task being monitored. But to be consistent with previous APIs that use setValue(), and to provide a more intuitive API, the value attribute is used in Swing.)
A JProgressBar-derived component is specifically designed to provide a bar-graph-style progress indicator. Many other kinds of indicators, such as pie chart style indicators, could be implemented as subclasses of JProgressBar. But the pluggable-L&F capabilities of the JProgressBar class should be reserved for customizing the bar-graph-style indicator for different platforms.
Version 0.5. Last modified 09/04/97.
Copyright © 1995-97 Sun
Microsystems, Inc. All Rights Reserved.