|
|||||||||||
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
Safe: 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 java.beans.XMLEncoder
.
javax.swing.plaf.basic.BasicProgressBarUI
,
Serialized FormField 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. |
private static int |
defaultMaximum
The default maximum for a progress bar is 100. |
private static int |
defaultMinimum
The default minimum for a progress bar is 0. |
private static int |
defaultOrientation
The default orientation for a progress bar is HORIZONTAL . |
private java.text.Format |
format
Format used when displaying percent complete. |
private boolean |
indeterminate
Whether the progress bar is indeterminate ( true ) or
normal (false ); the default is false . |
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. |
private static String |
uiClassID
|
Fields inherited from class javax.swing.JComponent |
_bounds, accessibleContext, listenerList, paintingChild, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
Fields inherited from class java.awt.Container |
|
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, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST |
Constructor Summary | |
JProgressBar()
Enabled: Creates a horizontal progress bar that displays a border but no progress string. |
|
JProgressBar(BoundedRangeModel newModel)
Enabled: Creates a horizontal progress bar that uses the specified model to hold the progress bar's data. |
|
JProgressBar(int orient)
Enabled: Creates a progress bar with the specified orientation, which can be either JProgressBar.VERTICAL or
JProgressBar.HORIZONTAL . |
|
JProgressBar(int min,
int max)
Enabled: Creates a horizontal progress bar with the specified minimum and maximum. |
|
JProgressBar(int orient,
int min,
int max)
Enabled: Creates a progress bar using the specified orientation, minimum, and maximum. |
Method Summary | |
void |
addChangeListener(ChangeListener l)
Enabled: 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 ChangeEvent s. |
AccessibleContext |
getAccessibleContext()
Suppressed: Gets the AccessibleContext associated with this
JProgressBar . |
ChangeListener[] |
getChangeListeners()
Suppressed: Returns an array of all the ChangeListener s added
to this progress bar with addChangeListener . |
int |
getMaximum()
Enabled: Returns the progress bar's maximum value, which is stored in the progress bar's BoundedRangeModel . |
int |
getMinimum()
Enabled: Returns the progress bar's minimum value, which is stored in the progress bar's BoundedRangeModel . |
BoundedRangeModel |
getModel()
Enabled: Returns the data model used by this progress bar. |
int |
getOrientation()
Enabled: Returns JProgressBar.VERTICAL or
JProgressBar.HORIZONTAL , depending on the orientation
of the progress bar. |
double |
getPercentComplete()
Enabled: Returns the percent complete for the progress bar. |
String |
getString()
Enabled: Returns the current value of the progress string. |
javax.swing.plaf.ProgressBarUI |
getUI()
Suppressed: Returns the look-and-feel object that renders this component. |
String |
getUIClassID()
Suppressed: Returns the name of the look-and-feel class that renders this component. |
int |
getValue()
Enabled: Returns the progress bar's current value, which is stored in the progress bar's BoundedRangeModel . |
boolean |
isBorderPainted()
Enabled: Returns the borderPainted property. |
boolean |
isIndeterminate()
Enabled: Returns the value of the indeterminate property. |
boolean |
isStringPainted()
Enabled: Returns the value of the stringPainted property. |
protected void |
paintBorder(Graphics g)
Paints the progress bar's border if the borderPainted
property is true . |
protected String |
paramString()
Returns a string representation of this JProgressBar . |
void |
removeChangeListener(ChangeListener l)
Enabled: Removes a ChangeListener from the progress bar. |
void |
setBorderPainted(boolean b)
Enabled: Sets the borderPainted property, which is
true if the progress bar should paint its border. |
void |
setIndeterminate(boolean newValue)
Enabled: Sets the indeterminate property of the progress bar,
which determines whether the progress bar is in determinate
or indeterminate mode. |
void |
setMaximum(int n)
Enabled: Sets the progress bar's maximum value (stored in the progress bar's data model) to n . |
void |
setMinimum(int n)
Enabled: Sets the progress bar's minimum value (stored in the progress bar's data model) to n . |
void |
setModel(BoundedRangeModel newModel)
Enabled: Sets the data model used by the JProgressBar . |
void |
setOrientation(int newOrientation)
Enabled: Sets the progress bar's orientation to newOrientation ,
which must be JProgressBar.VERTICAL or
JProgressBar.HORIZONTAL . |
void |
setString(String s)
Enabled: Sets the value of the progress string. |
void |
setStringPainted(boolean b)
Enabled: Sets the value of the stringPainted property,
which determines whether the progress bar
should render a progress string. |
void |
setUI(javax.swing.plaf.ProgressBarUI ui)
Suppressed: Sets the look-and-feel object that renders this component. |
void |
setValue(int n)
Enabled: Sets the progress bar's current value (stored in the progress bar's data model) to n . |
void |
updateUI()
Suppressed: Resets the UI property to a value from the current look and feel. |
private void |
writeObject(ObjectOutputStream s)
See readObject() and writeObject() in JComponent for more information about serialization in Swing. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
private static final String uiClassID
getUIClassID()
protected int orientation
HORIZONTAL
.
setOrientation(int)
protected boolean paintBorder
true
.
setBorderPainted(boolean)
protected BoundedRangeModel model
setModel(javax.swing.BoundedRangeModel)
protected String progressString
null
. Setting this to a non-null
value does not imply that the string will be displayed.
setString(java.lang.String)
protected boolean paintString
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.
setStringPainted(boolean)
private static final int defaultMinimum
private static final int defaultMaximum
private static final int defaultOrientation
HORIZONTAL
.
protected transient ChangeEvent changeEvent
ChangeEvent
is needed per instance since the
event's only interesting property is the immutable source, which
is the progress bar.
protected ChangeListener changeListener
createChangeListener()
private transient java.text.Format format
private boolean indeterminate
true
) or
normal (false
); the default is false
.
setIndeterminate(boolean)
Constructor Detail |
public JProgressBar()
setOrientation(int)
,
setBorderPainted(boolean)
,
setStringPainted(boolean)
,
setString(java.lang.String)
,
setIndeterminate(boolean)
public JProgressBar(int orient)
JProgressBar.VERTICAL
or
JProgressBar.HORIZONTAL
.
By default, a border is painted but a progress string is not.
The initial and minimum values are 0,
and the maximum is 100.
orient
- the desired orientation of the progress barsetOrientation(int)
,
setBorderPainted(boolean)
,
setStringPainted(boolean)
,
setString(java.lang.String)
,
setIndeterminate(boolean)
public JProgressBar(int min, int max)
BoundedRangeModel
that holds the progress bar's data
handles any issues that may arise from improperly setting the
minimum, initial, and maximum values on the progress bar.
min
- the minimum value of the progress barmax
- the maximum value of the progress barBoundedRangeModel
,
setOrientation(int)
,
setBorderPainted(boolean)
,
setStringPainted(boolean)
,
setString(java.lang.String)
,
setIndeterminate(boolean)
public JProgressBar(int orient, int min, int max)
BoundedRangeModel
that holds the progress bar's data
handles any issues that may arise from improperly setting the
minimum, initial, and maximum values on the progress bar.
orient
- the desired orientation of the progress barmin
- the minimum value of the progress barmax
- the maximum value of the progress barBoundedRangeModel
,
setOrientation(int)
,
setBorderPainted(boolean)
,
setStringPainted(boolean)
,
setString(java.lang.String)
,
setIndeterminate(boolean)
public JProgressBar(BoundedRangeModel newModel)
newModel
- the data model for the progress barsetOrientation(int)
,
setBorderPainted(boolean)
,
setStringPainted(boolean)
,
setString(java.lang.String)
,
setIndeterminate(boolean)
Method Detail |
public int getOrientation()
JProgressBar.VERTICAL
or
JProgressBar.HORIZONTAL
, depending on the orientation
of the progress bar. The default orientation is
HORIZONTAL
.
HORIZONTAL
or VERTICAL
setOrientation(int)
public void setOrientation(int newOrientation)
newOrientation
,
which must be JProgressBar.VERTICAL
or
JProgressBar.HORIZONTAL
. The default orientation
is HORIZONTAL
.
newOrientation
- HORIZONTAL
or VERTICAL
getOrientation()
public boolean isStringPainted()
stringPainted
property.
stringPainted
propertysetStringPainted(boolean)
,
setString(java.lang.String)
public void setStringPainted(boolean b)
stringPainted
property,
which determines whether the progress bar
should render a progress string.
The default is false
:
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.
b
- true
if the progress bar should render a stringisStringPainted()
,
setString(java.lang.String)
public String getString()
setString
before
calling super.getString
.
setString(java.lang.String)
public void setString(String s)
null
.
If you have provided a custom progress string and want to revert to
the built-in behavior, set the string back to null
.
If you are providing a custom progress string
by overriding this method,
make sure that you call setString
before
calling getString
.
The progress string is painted only if
the isStringPainted
method returns true
.
s
- the value of the percent stringgetString()
,
setStringPainted(boolean)
,
isStringPainted()
public double getPercentComplete()
public boolean isBorderPainted()
borderPainted
property.
borderPainted
propertysetBorderPainted(boolean)
public void setBorderPainted(boolean b)
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.
b
- true
if the progress bar
should paint its border;
otherwise, false
isBorderPainted()
protected void paintBorder(Graphics g)
borderPainted
property is true
.
paintBorder
in class JComponent
g
- the Graphics
context within which to paint the borderJComponent.paint(java.awt.Graphics)
,
JComponent.setBorder(javax.swing.border.Border)
,
isBorderPainted()
,
setBorderPainted(boolean)
public javax.swing.plaf.ProgressBarUI getUI()
ProgressBarUI
object that renders this componentpublic void setUI(javax.swing.plaf.ProgressBarUI ui)
ui
- a ProgressBarUI
objectUIDefaults.getUI(javax.swing.JComponent)
public void updateUI()
updateUI
in class JComponent
JComponent.updateUI()
public String getUIClassID()
getUIClassID
in class JComponent
JComponent.getUIClassID()
,
UIDefaults.getUI(javax.swing.JComponent)
protected ChangeListener createChangeListener()
ChangeListener
implementation.
changeListener
,
javax.swing.event.ChangeListener
,
javax.swing.BoundedRangeModel
public void addChangeListener(ChangeListener l)
ChangeListener
to the progress bar.
l
- the ChangeListener
to addpublic void removeChangeListener(ChangeListener l)
ChangeListener
from the progress bar.
l
- the ChangeListener
to removepublic ChangeListener[] getChangeListeners()
ChangeListener
s added
to this progress bar with addChangeListener
.
ChangeListener
s added or an empty
array if no listeners have been addedprotected void fireStateChanged()
ChangeEvent
s.
The event instance
is created if necessary.
EventListenerList
public BoundedRangeModel getModel()
BoundedRangeModel
currently in useBoundedRangeModel
public void setModel(BoundedRangeModel newModel)
JProgressBar
.
newModel
- the BoundedRangeModel
to usepublic int getValue()
BoundedRangeModel
.
The value is always between the
minimum and maximum values, inclusive. By default, the
value is initialized to be equal to the minimum value.
setValue(int)
,
BoundedRangeModel.getValue()
public int getMinimum()
BoundedRangeModel
.
By default, the minimum value is 0
.
setMinimum(int)
,
BoundedRangeModel.getMinimum()
public int getMaximum()
BoundedRangeModel
.
By default, the maximum value is 100
.
setMaximum(int)
,
BoundedRangeModel.getMaximum()
public void setValue(int n)
n
.
The data model (a BoundedRangeModel
instance)
handles any mathematical
issues arising from assigning faulty values.
If the new value is different from the previous value, all change listeners are notified.
n
- the new valuegetValue()
,
BoundedRangeModel.setValue(int)
public void setMinimum(int n)
n
.
The data model (a BoundedRangeModel
instance)
handles any mathematical
issues arising from assigning faulty values.
If the minimum value is different from the previous minimum, all change listeners are notified.
n
- the new minimumgetMinimum()
,
addChangeListener(javax.swing.event.ChangeListener)
,
BoundedRangeModel.setMinimum(int)
public void setMaximum(int n)
n
.
The underlying BoundedRangeModel
handles any mathematical
issues arising from assigning faulty values.
If the maximum value is different from the previous maximum, all change listeners are notified.
n
- the new maximumgetMaximum()
,
addChangeListener(javax.swing.event.ChangeListener)
,
BoundedRangeModel.setMaximum(int)
public void setIndeterminate(boolean newValue)
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.
newValue
- true
if the progress bar
should change to indeterminate mode;
false
if it should revert to normal.isIndeterminate()
,
javax.swing.plaf.basic.BasicProgressBarUI
public boolean isIndeterminate()
indeterminate
property.
indeterminate
propertysetIndeterminate(boolean)
private void writeObject(ObjectOutputStream s) throws IOException
s
- the ObjectOutputStream
in which to write
IOException
protected String paramString()
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
.
paramString
in class JComponent
JProgressBar
public AccessibleContext getAccessibleContext()
AccessibleContext
associated with this
JProgressBar
. For progress bars, the
AccessibleContext
takes the form of an
AccessibleJProgressBar
.
A new AccessibleJProgressBar
instance is created if necessary.
getAccessibleContext
in interface Accessible
getAccessibleContext
in class JComponent
AccessibleJProgressBar
that serves as the
AccessibleContext
of this JProgressBar
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |