Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JProgressBar
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 |
|
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 |
|
protected ChangeListener |
|
protected BoundedRangeModel |
|
protected int |
|
protected boolean |
|
protected boolean |
|
protected String |
|
Fields inherited from class javax.swing.JComponent | |
TOOL_TIP_TEXT_KEY , UNDEFINED_CONDITION , WHEN_ANCESTOR_OF_FOCUSED_COMPONENT , WHEN_FOCUSED , WHEN_IN_FOCUSED_WINDOW , accessibleContext , listenerList , ui |
Fields inherited from class java.awt.Component | |
BOTTOM_ALIGNMENT , CENTER_ALIGNMENT , LEFT_ALIGNMENT , RIGHT_ALIGNMENT , TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver | |
ABORT , ALLBITS , ERROR , FRAMEBITS , HEIGHT , PROPERTIES , SOMEBITS , WIDTH |
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 | |
| |
| |
| |
| |
|
Method Summary | |
void |
|
protected ChangeListener |
|
protected void |
|
AccessibleContext |
|
ChangeListener[] |
|
int |
|
int |
|
BoundedRangeModel |
|
int |
|
double |
|
String |
|
ProgressBarUI |
|
String |
|
int |
|
boolean |
|
boolean |
|
boolean |
|
protected void |
|
protected String |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
protected ChangeEvent changeEvent
A single change event reused for all events.
- See Also:
fireStateChanged()
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.
- See Also:
setModel(BoundedRangeModel)
protected int orientation
The orientation of theJProgressBar
(SwingConstants.HORIZONTAL
orSwingConstants.VERTICAL
). Defaults toSwingConstants.HORIZONTAL
.
- See Also:
setOrientation(int)
protected boolean paintBorder
A flag the controls whether or not the component's border is painted. The default istrue
.
- See Also:
setBorderPainted(boolean)
protected boolean paintString
A flag that controls whether a string is displayed within the progress bar.
- See Also:
setStringPainted(boolean)
protected String progressString
A custom string for display in the progress bar. If this isnull
, a default string will be generated.
- See Also:
setString(String)
public JProgressBar()
Creates a newJProgressBar
with default attributes. The following defaults are used:
value
: 0;minimum
: 0;maximum
: 100;orientation
:SwingConstants.HORIZONTAL
.
public JProgressBar(int orientation)
Creates a newJProgressBar
with the specifiedorientation
. The following defaults are used:
value
: 0;minimum
: 0;maximum
: 100;
- Parameters:
orientation
- the orientation (SwingConstants.HORIZONTAL
orSwingConstants.VERTICAL
).
- Throws:
IllegalArgumentException
- iforientation
is not one of the specified values.
public JProgressBar(int minimum, int maximum)
Creates a newJProgressBar
with the specified value range. The following defaults are used:
value
:minimum
;orientation
:SwingConstants.HORIZONTAL
.
- Parameters:
minimum
- the lower bound of the value range.maximum
- the upper bound of the value range.
public JProgressBar(int orientation, int minimum, int maximum)
Creates a newJProgressBar
with the specified range and orientation. The following defaults are used:
value
:minimum
;
- Parameters:
orientation
- the orientation (SwingConstants.HORIZONTAL
orSwingConstants.VERTICAL
).minimum
- the lower bound of the value range.maximum
- the upper bound of the value range.
- Throws:
IllegalArgumentException
- iforientation
is not one of the specified values.
public JProgressBar(BoundedRangeModel model)
Creates a newJProgressBar
with the specified model. The following defaults are used:
orientation
:SwingConstants.HORIZONTAL
.
- Parameters:
model
- the model (null
not permitted).
public void addChangeListener(ChangeListener listener)
Registers a listener with this component so that it will receive notification of component state changes.
- Parameters:
listener
- the listener.
- See Also:
removeChangeListener(ChangeListener)
protected ChangeListener createChangeListener()
Creates a newChangeListener
that callsfireStateChanged()
whenever it receives aChangeEvent
(typically from the component'smodel
). 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.
- Returns:
- A new listener.
protected void fireStateChanged()
Sends aChangeEvent
to all registered listeners to indicate that the state of theJProgressBar
has changed.
- See Also:
createChangeListener()
public AccessibleContext getAccessibleContext()
Returns the object that provides accessibility features for thisJProgressBar
component.
- Specified by:
- getAccessibleContext in interface Accessible
- Overrides:
- getAccessibleContext in interface JComponent
- Returns:
- The accessible context (an instance of
JProgressBar.AccessibleJProgressBar
).
public ChangeListener[] getChangeListeners()
Returns an array of the listeners that are registered with this component. The array may be empty, but is nevernull
.
- Returns:
- An array of listeners.
- Since:
- 1.4
public int getMaximum()
Returns the maximum value for theJProgressBar
. This defines the upper bound for the current value, and is stored in the component'smodel
.
- Returns:
- The maximum value.
- See Also:
setMaximum(int)
public int getMinimum()
Returns the minimum value for theJProgressBar
. This defines the lower bound for the current value, and is stored in the component'smodel
.
- Returns:
- The minimum value.
- See Also:
setMinimum(int)
public BoundedRangeModel getModel()
Returns the model for theJProgressBar
.
- Returns:
- The model (never
null
).
- See Also:
setModel(BoundedRangeModel)
public int getOrientation()
Returns the orientation of theJProgressBar
component, which is eitherSwingConstants.HORIZONTAL
orSwingConstants.VERTICAL
. The default orientation isHORIZONTAL
.
- Returns:
- The orientation.
- See Also:
setOrientation(int)
public double getPercentComplete()
Returns the current value expressed as a percentage. This is calculated as(value - min) / (max - min)
.
- Returns:
- The percentage (a value in the range 0.0 to 1.0).
public String getString()
Returns the string that is painted on theJProgressBar
ifisStringPainted()
returnstrue
. If no string has been explicitly set, this method will return a string displaying the value ofgetPercentComplete()
.
- Returns:
- The string.
- See Also:
setString(String)
,setStringPainted(boolean)
public ProgressBarUI getUI()
Returns the UI delegate for thisJProgressBar
.
- Returns:
- The UI delegate.
public 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 aJProgressBar
.
- Overrides:
- getUIClassID in interface JComponent
- Returns:
"ProgressBarUI"
.
public int getValue()
Returns the current value for theJProgressBar
. This value is fetched from the model.
- Returns:
- The current value.
- See Also:
setValue(int)
public boolean isBorderPainted()
Returns a flag that controls whether or not the component's border is painted. The default value istrue
.
- Returns:
true
if the component's border should be painted, andfalse
otherwise.
- See Also:
setBorderPainted(boolean)
public boolean isIndeterminate()
Returns a flag that indicates the mode for thisJProgressBar
(true
for indeterminate mode, andfalse
for determinate mode).
- Returns:
- A flag indicating the mode for the
JProgressBar
.
- Since:
- 1.4
- See Also:
setIndeterminate(boolean)
public boolean isStringPainted()
Returns the flag that controls whether or not the string returned bygetString()
is displayed by theJProgressBar
component.
- Returns:
true
if the string should be displayed, andfalse
otherwise.
- See Also:
setStringPainted(boolean)
protected void paintBorder(Graphics graphics)
Paints the component's border, but only ifisBorderPainted()
returnstrue
.
- Overrides:
- paintBorder in interface JComponent
- Parameters:
graphics
- the graphics object to paint with.
- See Also:
setBorderPainted(boolean)
protected String paramString()
Returns an implementation-dependent string describing the attributes of thisJProgressBar
.
- Overrides:
- paramString in interface JComponent
- Returns:
- A string describing the attributes of this
JProgressBar
(nevernull
).
public void removeChangeListener(ChangeListener listener)
Deregisters a listener so that it no longer receives notification of component state changes.
- Parameters:
listener
- the listener.
- See Also:
addChangeListener(ChangeListener)
public void setBorderPainted(boolean painted)
Sets the flag that controls whether or not the component's border is painted. If the flag value is changed, this method sends aPropertyChangeEvent
(with the property name "borderPainted") to all registered listeners.
- Parameters:
painted
- the new flag value.
- See Also:
isBorderPainted()
,paintBorder
public void setIndeterminate(boolean flag)
Sets the flag that controls the mode for thisJProgressBar
(true
for indeterminate mode, andfalse
for determinate mode). If the flag value changes, this method sends aPropertyChangeEvent
(with the property name"indeterminate"
) to all registered listeners. If theJProgressBar
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 theJProgressBar
is ignored.
- Parameters:
flag
- the new flag value.
- Since:
- 1.4
- See Also:
isIndeterminate()
public void setMaximum(int maximum)
Sets the maximum value for theJProgressBar
. The value is stored in the component'smodel
(seegetModel()
). If the new value is different to the old value, aChangeEvent
is sent to the model's registered listeners. In turn, this triggers a call tofireStateChanged()
which will send aChangeEvent
to this component's registered listeners.
- Parameters:
maximum
- the maximum value.
- See Also:
getMaximum()
public void setMinimum(int minimum)
Sets the minimum value for theJProgressBar
. The value is stored in the component'smodel
(seegetModel()
). If the new value is different to the old value, aChangeEvent
is sent to the model's registered listeners. In turn, this triggers a call tofireStateChanged()
which will send aChangeEvent
to this component's registered listeners.
- Parameters:
minimum
- the minimum value.
- See Also:
getMinimum()
public void setModel(BoundedRangeModel model)
Sets the model for theJProgressBar
and sends aChangeEvent
to all registered listeners.
- Parameters:
model
- the model (null
not permitted).
- See Also:
getModel()
public void setOrientation(int orientation)
Sets the orientation for thisJProgressBar
component and, if the value changes, sends aPropertyChangeEvent
(with the property name"orientation"
) to all registered listeners.
- Parameters:
orientation
- the orientation (SwingConstants.HORIZONTAL
orSwingConstants.VERTICAL
).
- Throws:
IllegalArgumentException
- iforientation
is not one of the listed values.
- See Also:
getOrientation()
public 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 aPropertyChangeEvent
(with the property name"string"
) to all registered listeners. If the string is set tonull
,getString()
will return a default string.
- Parameters:
string
- the string (null
permitted).
- See Also:
getString()
,setStringPainted(boolean)
public void setStringPainted(boolean painted)
Sets the flag that controls whether or not the string returned bygetString()
is displayed by theJProgressBar
component. If the flag value changes, aPropertyChangeEvent
(with the property name"stringPainted"
) is sent to all registered listeners.
- Parameters:
painted
- the new flag value.
- See Also:
isStringPainted()
,setString(String)
public void setUI(ProgressBarUI ui)
Sets the UI delegate for this component.
- Parameters:
ui
- the new UI delegate.
public void setValue(int value)
Sets the current value for theJProgressBar
. The value is stored in the component'smodel
(seegetModel()
). If the new value is different to the old value, aChangeEvent
is sent to the model's registered listeners. In turn, this triggers a call tofireStateChanged()
which will send aChangeEvent
to this component's registered listeners. Ifvalue
is outside the rangeminimum
tomaximum
, it will be set to the nearest of those boundary values.
- Parameters:
value
- the new value.
- See Also:
getValue()
public void updateUI()
Sets thisJProgressBar
's UI delegate to the default (obtained from theUIManager
) for the current look and feel.
- Overrides:
- updateUI in interface JComponent