|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JProgressBar
public class JProgressBar
A component that displays a visual indicator of the progress of a task. The
component has two modes: determinate and indeterminate. In determinate mode,
the JProgressBar
fills a percentage of its bar based on its
current value. In indeterminate mode, it creates box and bounces it between
its bounds.
This component has the following properties:
Property | Stored in | Bound? |
---|---|---|
borderPainted | progressBar | yes |
changeListeners | progressBar | no |
indeterminate | progressBar | yes |
maximum | model | no |
minimum | model | no |
model | progressBar | no |
orientation | progressBar | yes |
percentComplete | progressBar | no |
string | progressBar | yes |
stringPainted | progressBar | yes |
value | model | no |
Nested Class Summary | |
---|---|
protected class |
JProgressBar.AccessibleJProgressBar
Provides the accessibility features for the JProgressBar
component. |
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, Component.BltBufferStrategy, Component.FlipBufferStrategy |
Field Summary | |
---|---|
protected ChangeEvent |
changeEvent
A single change event reused for all events. |
protected ChangeListener |
changeListener
The listener that is registered with the model. |
protected BoundedRangeModel |
model
The model defining the bounds and current value for the progress bar. |
protected int |
orientation
The orientation of the JProgressBar
(SwingConstants.HORIZONTAL or SwingConstants.VERTICAL ). |
protected boolean |
paintBorder
A flag the controls whether or not the component's border is painted. |
protected boolean |
paintString
A flag that controls whether a string is displayed within the progress bar. |
protected String |
progressString
A custom string for display in 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, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
JProgressBar()
Creates a new JProgressBar with default attributes. |
|
JProgressBar(BoundedRangeModel model)
Creates a new JProgressBar with the specified model. |
|
JProgressBar(int orientation)
Creates a new JProgressBar with the specified
orientation . |
|
JProgressBar(int minimum,
int maximum)
Creates a new JProgressBar with the specified value range. |
|
JProgressBar(int orientation,
int minimum,
int maximum)
Creates a new JProgressBar with the specified range and
orientation. |
Method Summary | |
---|---|
void |
addChangeListener(ChangeListener listener)
Registers a listener with this component so that it will receive notification of component state changes. |
protected ChangeListener |
createChangeListener()
Creates a new ChangeListener that calls
fireStateChanged() whenever it receives a ChangeEvent
(typically from the component's model ). |
protected void |
fireStateChanged()
Sends a ChangeEvent to all registered listeners to indicate that
the state of the JProgressBar has changed. |
AccessibleContext |
getAccessibleContext()
Returns the object that provides accessibility features for this JProgressBar component. |
ChangeListener[] |
getChangeListeners()
Returns an array of the listeners that are registered with this component. |
int |
getMaximum()
Returns the maximum value for the JProgressBar . |
int |
getMinimum()
Returns the minimum value for the JProgressBar . |
BoundedRangeModel |
getModel()
Returns the model for the JProgressBar . |
int |
getOrientation()
Returns the orientation of the JProgressBar component, which
is either SwingConstants.HORIZONTAL or
SwingConstants.VERTICAL . |
double |
getPercentComplete()
Returns the current value expressed as a percentage. |
String |
getString()
Returns the string that is painted on the JProgressBar if
isStringPainted() returns true . |
ProgressBarUI |
getUI()
Returns the UI delegate for this JProgressBar . |
String |
getUIClassID()
Returns the suffix ( "ProgressBarUI" in this case) used to
determine the class name for a UI delegate that can provide the look and
feel for a JProgressBar . |
int |
getValue()
Returns the current value for the JProgressBar . |
boolean |
isBorderPainted()
Returns a flag that controls whether or not the component's border is painted. |
boolean |
isIndeterminate()
Returns a flag that indicates the mode for this JProgressBar
(true for indeterminate mode, and false for
determinate mode). |
boolean |
isStringPainted()
Returns the flag that controls whether or not the string returned by getString() is displayed by the JProgressBar
component. |
protected void |
paintBorder(Graphics graphics)
Paints the component's border, but only if isBorderPainted()
returns true . |
protected String |
paramString()
Returns an implementation-dependent string describing the attributes of this JProgressBar . |
void |
removeChangeListener(ChangeListener listener)
Deregisters a listener so that it no longer receives notification of component state changes. |
void |
setBorderPainted(boolean painted)
Sets the flag that controls whether or not the component's border is painted. |
void |
setIndeterminate(boolean flag)
Sets the flag that controls the mode for this JProgressBar
(true for indeterminate mode, and false for
determinate mode). |
void |
setMaximum(int maximum)
Sets the maximum value for the JProgressBar . |
void |
setMinimum(int minimum)
Sets the minimum value for the JProgressBar . |
void |
setModel(BoundedRangeModel model)
Sets the model for the JProgressBar and sends a
ChangeEvent to all registered listeners. |
void |
setOrientation(int orientation)
Sets the orientation for this JProgressBar component and,
if the value changes, sends a PropertyChangeEvent (with the
property name "orientation" ) to all registered listeners. |
void |
setString(String string)
Sets the string to display within the progress bar and, if the new value is different to the old value, sends a PropertyChangeEvent (with
the property name "string" ) to all registered listeners. |
void |
setStringPainted(boolean painted)
Sets the flag that controls whether or not the string returned by getString() is displayed by the JProgressBar
component. |
void |
setUI(ProgressBarUI ui)
Sets the UI delegate for this component. |
void |
setValue(int value)
Sets the current value for the JProgressBar . |
void |
updateUI()
Sets this JProgressBar 's UI delegate to the default
(obtained from the UIManager ) for the current look and feel. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected int orientation
JProgressBar
(SwingConstants.HORIZONTAL
or SwingConstants.VERTICAL
).
Defaults to SwingConstants.HORIZONTAL
.
setOrientation(int)
protected boolean paintBorder
true
.
setBorderPainted(boolean)
protected BoundedRangeModel model
setModel(BoundedRangeModel)
protected String progressString
null
, a default string will be generated.
setString(String)
protected boolean paintString
setStringPainted(boolean)
protected transient ChangeEvent changeEvent
fireStateChanged()
protected ChangeListener changeListener
Constructor Detail |
---|
public JProgressBar()
JProgressBar
with default attributes. The
following defaults are used:
value
: 0;minimum
: 0;maximum
: 100;orientation
: SwingConstants.HORIZONTAL
.
public JProgressBar(int orientation)
JProgressBar
with the specified
orientation
. The following defaults are used:
value
: 0;minimum
: 0;maximum
: 100;
orientation
- the orientation (SwingConstants.HORIZONTAL
or
SwingConstants.VERTICAL
).
IllegalArgumentException
- if orientation
is not one of
the specified values.public JProgressBar(int minimum, int maximum)
JProgressBar
with the specified value range.
The following defaults are used:
value
: minimum
;orientation
: SwingConstants.HORIZONTAL
.
minimum
- the lower bound of the value range.maximum
- the upper bound of the value range.public JProgressBar(int orientation, int minimum, int maximum)
JProgressBar
with the specified range and
orientation. The following defaults are used:
value
: minimum
;
minimum
- the lower bound of the value range.maximum
- the upper bound of the value range.orientation
- the orientation (SwingConstants.HORIZONTAL
or
SwingConstants.VERTICAL
).
IllegalArgumentException
- if orientation
is not one of
the specified values.public JProgressBar(BoundedRangeModel model)
JProgressBar
with the specified model. The
following defaults are used:
orientation
: SwingConstants.HORIZONTAL
.
model
- the model (null
not permitted).Method Detail |
---|
public int getValue()
JProgressBar
. This value
is fetched from the model.
setValue(int)
public void setValue(int value)
JProgressBar
. The value is
stored in the component's model
(see getModel()
).
If the new value is different to the old value, a ChangeEvent
is
sent to the model's registered listeners. In turn, this triggers a call
to fireStateChanged()
which will send a ChangeEvent
to this component's registered listeners.
If value
is outside the range minimum
to
maximum
, it will be set to the nearest of those boundary
values.
value
- the new value.getValue()
protected void paintBorder(Graphics graphics)
isBorderPainted()
returns true
.
paintBorder
in class JComponent
graphics
- the graphics object to paint with.setBorderPainted(boolean)
public int getOrientation()
JProgressBar
component, which
is either SwingConstants.HORIZONTAL
or
SwingConstants.VERTICAL
. The default orientation is
HORIZONTAL
.
setOrientation(int)
public void setOrientation(int orientation)
JProgressBar
component and,
if the value changes, sends a PropertyChangeEvent
(with the
property name "orientation"
) to all registered listeners.
orientation
- the orientation (SwingConstants.HORIZONTAL
or
SwingConstants.VERTICAL
).
IllegalArgumentException
- if orientation
is not
one of the listed values.getOrientation()
public boolean isStringPainted()
getString()
is displayed by the JProgressBar
component.
true
if the string should be displayed, and
false
otherwise.setStringPainted(boolean)
public void setStringPainted(boolean painted)
getString()
is displayed by the JProgressBar
component. If the flag value changes, a PropertyChangeEvent
(with
the property name "stringPainted"
) is sent to all registered
listeners.
painted
- the new flag value.isStringPainted()
,
setString(String)
public String getString()
JProgressBar
if
isStringPainted()
returns true
. If no string has
been explicitly set, this method will return a string displaying the
value of getPercentComplete()
.
setString(String)
,
setStringPainted(boolean)
public void setString(String string)
PropertyChangeEvent
(with
the property name "string"
) to all registered listeners. If
the string is set to null
, getString()
will return
a default string.
string
- the string (null
permitted).getString()
,
setStringPainted(boolean)
public double getPercentComplete()
(value - min) / (max - min)
.
public boolean isBorderPainted()
true
.
true
if the component's border should be painted,
and false
otherwise.setBorderPainted(boolean)
public void setBorderPainted(boolean painted)
PropertyChangeEvent
(with the property name "borderPainted") to
all registered listeners.
painted
- the new flag value.isBorderPainted()
,
paintBorder
public ProgressBarUI getUI()
JProgressBar
.
public void setUI(ProgressBarUI ui)
ui
- the new UI delegate.public void updateUI()
JProgressBar
's UI delegate to the default
(obtained from the UIManager
) for the current look and feel.
updateUI
in class JComponent
public String getUIClassID()
"ProgressBarUI"
in this case) used to
determine the class name for a UI delegate that can provide the look and
feel for a JProgressBar
.
getUIClassID
in class JComponent
"ProgressBarUI"
.JComponent.setUI(javax.swing.plaf.ComponentUI)
,
JComponent.updateUI()
protected ChangeListener createChangeListener()
ChangeListener
that calls
fireStateChanged()
whenever it receives a ChangeEvent
(typically from the component's model
). This listener is
registered with the progress bar's model, so that changes made to the
model directly will automatically result in the progress bar's listeners
being notified also.
public void addChangeListener(ChangeListener listener)
listener
- the listener.removeChangeListener(ChangeListener)
public void removeChangeListener(ChangeListener listener)
listener
- the listener.addChangeListener(ChangeListener)
public ChangeListener[] getChangeListeners()
null
.
protected void fireStateChanged()
ChangeEvent
to all registered listeners to indicate that
the state of the JProgressBar
has changed.
createChangeListener()
public BoundedRangeModel getModel()
JProgressBar
.
null
).setModel(BoundedRangeModel)
public void setModel(BoundedRangeModel model)
JProgressBar
and sends a
ChangeEvent
to all registered listeners.
model
- the model (null
not permitted).getModel()
public int getMinimum()
JProgressBar
. This defines
the lower bound for the current value, and is stored in the component's
model
.
setMinimum(int)
public void setMinimum(int minimum)
JProgressBar
. The value is
stored in the component's model
(see getModel()
).
If the new value is different to the old value, a ChangeEvent
is
sent to the model's registered listeners. In turn, this triggers a call
to fireStateChanged()
which will send a ChangeEvent
to this component's registered listeners.
minimum
- the minimum value.getMinimum()
public int getMaximum()
JProgressBar
. This defines
the upper bound for the current value, and is stored in the component's
model
.
setMaximum(int)
public void setMaximum(int maximum)
JProgressBar
. The value is
stored in the component's model
(see getModel()
).
If the new value is different to the old value, a ChangeEvent
is
sent to the model's registered listeners. In turn, this triggers a call
to fireStateChanged()
which will send a ChangeEvent
to this component's registered listeners.
maximum
- the maximum value.getMaximum()
protected String paramString()
JProgressBar
.
paramString
in class JComponent
JProgressBar
(never null
).public void setIndeterminate(boolean flag)
JProgressBar
(true
for indeterminate mode, and false
for
determinate mode). If the flag value changes, this method sends a
PropertyChangeEvent
(with the property name
"indeterminate"
) to all registered listeners.
If the JProgressBar
is determinate, it paints a percentage
of the bar described by its value. If it is indeterminate, it simply
bounces a box between the ends of the bar; the value of the
JProgressBar
is ignored.
flag
- the new flag value.isIndeterminate()
public boolean isIndeterminate()
JProgressBar
(true
for indeterminate mode, and false
for
determinate mode).
JProgressBar
.setIndeterminate(boolean)
public AccessibleContext getAccessibleContext()
JProgressBar
component.
getAccessibleContext
in interface Accessible
getAccessibleContext
in class JComponent
JProgressBar.AccessibleJProgressBar
).
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |