Top Description Inners Fields Constructors Methods
javax.swing

public Class JProgressBar

extends JComponent
implements SwingConstants, Accessible
Class Inheritance
All Implemented Interfaces
javax.accessibility.Accessible, javax.swing.SwingConstants
Annotations
@JavaBean
defaultProperty:UI
description:A component that displays an integer value.
@SwingContainer:false
@SuppressWarnings:serial
Imports
java.awt.Graphics, java.beans.BeanProperty, .JavaBean, java.io.IOException, .ObjectOutputStream, .Serial, .Serializable, java.text.Format, .NumberFormat, javax.accessibility.Accessible, .AccessibleContext, .AccessibleRole, .AccessibleState, .AccessibleStateSet, .AccessibleValue, javax.swing.event.ChangeEvent, .ChangeListener, .EventListenerList, javax.swing.plaf.ProgressBarUI

A component that visually displays the progress of some task. As the task progresses towards completion, the progress bar displays the task's percentage of completion. This percentage is typically represented visually by a rectangle which starts out empty and gradually becomes filled in as the task progresses. In addition, the progress bar can display a textual representation of this percentage.

JProgressBar uses a BoundedRangeModel as its data model, with the value property representing the "current" state of the task, and the minimum and maximum properties representing the beginning and end points, respectively.

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 (representing some piece of work) which returns information about the progress of the task:

progressBar = new JProgressBar(0, task.getLengthOfTask());
progressBar.setValue(0);
progressBar.setStringPainted(true);
Here is an example of querying the current state of the task, and using the returned value to update 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

Swing is not thread safe. For more information see Swing's Threading Policy.

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 JavaBeans has been added to the java.beans package. Please see java.beans.XMLEncoder.

Authors
Michael C. Albers, Kathy Walrath
Since
1.2
See Also
javax.swing.plaf.basic.BasicProgressBarUI, javax.swing.BoundedRangeModel, javax.swing.SwingWorker

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected class
JProgressBar.AccessibleJProgressBar

This class implements accessibility support for the JProgressBar class.

private class

Field Summary

Modifier and TypeField and Description
protected transient 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 final int
defaultMaximum

The default maximum for a progress bar is 100.

private static final int
defaultMinimum

The default minimum for a progress bar is 0.

private static final int
defaultOrientation

The default orientation for a progress bar is HORIZONTAL.

private transient 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 display a string of text on the progress bar.

protected String
progressString

An optional string that can be displayed on the progress bar.

private static final String
Inherited from javax.swing.JComponent:
DEBUG_GRAPHICS_LOADEDfocusControllerlistenerListpaintingChildTOOL_TIP_TEXT_KEYuiUNDEFINED_CONDITIONWHEN_ANCESTOR_OF_FOCUSED_COMPONENTWHEN_FOCUSEDWHEN_IN_FOCUSED_WINDOW

Constructor Summary

AccessConstructor and Description
public
JProgressBar()

Creates a horizontal progress bar that displays a border but no progress string.

public
JProgressBar(int
the desired orientation of the progress bar
orient
)

Creates a progress bar with the specified orientation, which can be either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL.

public
JProgressBar(int
the minimum value of the progress bar
min
,
int
the maximum value of the progress bar
max
)

Creates a horizontal progress bar with the specified minimum and maximum.

public
JProgressBar(int
the desired orientation of the progress bar
orient
,
int
the minimum value of the progress bar
min
,
int
the maximum value of the progress bar
max
)

Creates a progress bar using the specified orientation, minimum, and maximum.

public
JProgressBar(BoundedRangeModel
the data model for the progress bar
newModel
)

Creates a horizontal progress bar that uses the specified model to hold the progress bar's data.

Method Summary

Modifier and TypeMethod and Description
public void
addChangeListener(ChangeListener
the ChangeListener to add
l
)

Adds the specified ChangeListener to the progress bar.

protected ChangeListener

Returns:

the instance of a custom ChangeListener implementation.
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()

Send a ChangeEvent, whose source is this JProgressBar, to all ChangeListeners that have registered interest in ChangeEvents.

public AccessibleContext

Returns:

an AccessibleJProgressBar that serves as the AccessibleContext of this JProgressBar
getAccessibleContext
()

Overrides java.awt.Component.getAccessibleContext.

Implements javax.accessibility.Accessible.getAccessibleContext.

Gets the AccessibleContext associated with this JProgressBar.
public ChangeListener[]

Returns:

all of the ChangeListeners added or an empty array if no listeners have been added
getChangeListeners
()

Returns an array of all the ChangeListeners added to this progress bar with addChangeListener.

public int

Returns:

the progress bar's maximum value
getMaximum
()

Returns the progress bar's maximum value from the BoundedRangeModel.

public int

Returns:

the progress bar's minimum value
getMinimum
()

Returns the progress bar's minimum value from the BoundedRangeModel.

public BoundedRangeModel

Returns:

the BoundedRangeModel currently in use
getModel
()

Returns the data model used by this progress bar.

public int

Returns:

HORIZONTAL or VERTICAL
getOrientation
()

Returns SwingConstants.VERTICAL or SwingConstants.HORIZONTAL, depending on the orientation of the progress bar.

public double

Returns:

the percent complete for this progress bar
getPercentComplete
()

Returns the percent complete for the progress bar.

public String

Returns:

the value of the progress string, or a simple percentage string if the progress string is null
getString
()

Returns a String representation of the current progress.

public ProgressBarUI

Returns:

the ProgressBarUI object that renders this component
getUI
()

Overrides javax.swing.JComponent.getUI.

Returns the look-and-feel object that renders this component.
public String

Returns:

the string "ProgressBarUI"
getUIClassID
()

Overrides javax.swing.JComponent.getUIClassID.

Returns the name of the look-and-feel class that renders this component.
public int

Returns:

the current value of the progress bar
getValue
()

Returns the progress bar's current value from the BoundedRangeModel.

public boolean

Returns:

the value of the borderPainted property
isBorderPainted
()

Returns the borderPainted property.

public boolean

Returns:

the value of the indeterminate property
isIndeterminate
()

Returns the value of the indeterminate property.

public boolean

Returns:

the value of the stringPainted property
isStringPainted
()

Returns the value of the stringPainted property.

protected void
paintBorder(Graphics
the Graphics context within which to paint the border
g
)

Overrides javax.swing.JComponent.paintBorder.

Paints the progress bar's border if the borderPainted property is true.
protected String

Returns:

a string representation of this JProgressBar
paramString
()

Overrides javax.swing.JComponent.paramString.

Returns a string representation of this JProgressBar.
public void
removeChangeListener(ChangeListener
the ChangeListener to remove
l
)

Removes a ChangeListener from the progress bar.

public void
setBorderPainted(boolean
true if the progress bar should paint its border; otherwise, false
b
)

Sets the borderPainted property, which is true if the progress bar should paint its border.

public void
setIndeterminate(boolean
true if the progress bar should change to indeterminate mode; false if it should revert to normal.
newValue
)

Sets the indeterminate property of the progress bar, which determines whether the progress bar is in determinate or indeterminate mode.

public void
setMaximum(int
the new maximum
n
)

Sets the progress bar's maximum value (stored in the progress bar's data model) to n.

public void
setMinimum(int
the new minimum
n
)

Sets the progress bar's minimum value (stored in the progress bar's data model) to n.

public void
setModel(BoundedRangeModel
the BoundedRangeModel to use
newModel
)

Sets the data model used by the JProgressBar.

public void
setOrientation(int
HORIZONTAL or VERTICAL
newOrientation
)

Sets the progress bar's orientation to newOrientation, which must be SwingConstants.VERTICAL or SwingConstants.HORIZONTAL.

public void
setString(String
the value of the progress string
s
)

Sets the value of the progress string.

public void
setStringPainted(boolean
true if the progress bar should render a string
b
)

Sets the value of the stringPainted property, which determines whether the progress bar should render a progress string.

public void
setUI(ProgressBarUI
a ProgressBarUI object
ui
)

Sets the look-and-feel object that renders this component.

public void
setValue(int
the new value
n
)

Sets the progress bar's current value to n.

public void
updateUI()

Overrides javax.swing.JComponent.updateUI.

Resets the UI property to a value from the current look and feel.
private void
writeObject(ObjectOutputStream
the ObjectOutputStream in which to write
s
)

Hides javax.swing.JComponent.writeObject.

See readObject() and writeObject() in JComponent for more information about serialization in Swing.
Inherited from javax.swing.JComponent:
_paintImmediatelyaddAncestorListeneraddNotifyaddVetoableChangeListeneralwaysOnTopcheckIfChildObscuredBySiblingclientPropertyChangedcomponentInputMapChangedcomputeVisibleRectcomputeVisibleRectcompWriteObjectNotifycontainscreateToolTipdisabledndDonedropLocationForPointenablefirePropertyChangefirePropertyChangefirePropertyChangefireVetoableChangegetActionForKeyStrokegetActionMapgetActionMapgetAlignmentXgetAlignmentYgetAncestorListenersgetAutoscrollsgetBaselinegetBaselineResizeBehaviorgetBordergetBoundsgetClientPropertygetComponentGraphicsgetComponentPopupMenugetConditionForKeyStrokegetCreatedDoubleBuffergetDebugGraphicsOptionsgetDefaultLocalegetFontMetricsgetGraphicsgetGraphicsInvokedgetHeightgetInheritsPopupMenugetInputMapgetInputMapgetInputMapgetInputVerifiergetInsetsgetInsetsgetListenersgetLocationgetManagingFocusBackwardTraversalKeysgetManagingFocusForwardTraversalKeysgetMaximumSizegetMinimumSizegetNextFocusableComponentgetPopupLocationgetPreferredSizegetRegisteredKeyStrokesgetRootPanegetSizegetToolTipLocationgetToolTipTextgetToolTipTextgetTopLevelAncestorgetTransferHandlergetVerifyInputWhenFocusTargetgetVetoableChangeListenersgetVisibleRectgetWidthgetWriteObjCountergetXgetYgrabFocushideisDoubleBufferedisLightweightComponentisManagingFocusisOpaqueisOptimizedDrawingEnabledisPaintingisPaintingForPrintisPaintingOriginisPaintingTileisRequestFocusEnabledisValidateRootpaintpaintChildrenpaintComponentpaintForceDoubleBufferedpaintImmediatelypaintImmediatelypaintToOffscreenprintprintAllprintBorderprintChildrenprintComponentprocessComponentKeyEventprocessKeyBindingprocessKeyBindingsprocessKeyBindingsForAllComponentsprocessKeyEventprocessMouseEventprocessMouseMotionEventputClientPropertyrectangleIsObscuredregisterKeyboardActionregisterKeyboardActionremoveAncestorListenerremoveNotifyremoveVetoableChangeListenerrepaintrepaintrequestDefaultFocusrequestFocusrequestFocusrequestFocusInWindowrequestFocusInWindowresetKeyboardActionsreshaperevalidatesafelyGetGraphicssafelyGetGraphicsscrollRectToVisiblesetActionMapsetAlignmentXsetAlignmentYsetAutoscrollssetBackgroundsetBordersetComponentPopupMenusetCreatedDoubleBuffersetDebugGraphicsOptionssetDefaultLocalesetDoubleBufferedsetDropLocationsetEnabledsetFocusTraversalKeyssetFontsetForegroundsetInheritsPopupMenusetInputMapsetInputVerifiersetMaximumSizesetMinimumSizesetNextFocusableComponentsetOpaquesetPaintingChildsetPreferredSizesetRequestFocusEnabledsetToolTipTextsetTransferHandlersetUIsetUIPropertysetVerifyInputWhenFocusTargetsetVisiblesetWriteObjCountershouldDebugGraphicssuperProcessMouseMotionEventunregisterKeyboardActionupdate

Field Detail

changeEventback to summary
protected transient 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. The event is lazily created the first time that an event notification is fired.

See Also
fireStateChanged
changeListenerback to summary
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.

See Also
createChangeListener
defaultMaximumback to summary
private static final int defaultMaximum

The default maximum for a progress bar is 100.

defaultMinimumback to summary
private static final int defaultMinimum

The default minimum for a progress bar is 0.

defaultOrientationback to summary
private static final int defaultOrientation

The default orientation for a progress bar is HORIZONTAL.

formatback to summary
private transient Format format

Format used when displaying percent complete.

indeterminateback to summary
private boolean indeterminate

Whether the progress bar is indeterminate (true) or normal (false); the default is false.

Since
1.4
See Also
setIndeterminate
modelback to summary
protected BoundedRangeModel model

The object that holds the data for the progress bar.

See Also
setModel
orientationback to summary
protected int orientation

Whether the progress bar is horizontal or vertical. The default is HORIZONTAL.

See Also
setOrientation
paintBorderback to summary
protected boolean paintBorder

Whether to display a border around the progress bar. The default is true.

See Also
setBorderPainted
paintStringback to summary
protected boolean paintString

Whether to display a string of text on the progress bar. The default is 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.

See Also
setStringPainted, setString
progressStringback to summary
protected String progressString

An optional string that can be displayed on the progress bar. The default is null. Setting this to a non-null value does not imply that the string will be displayed. To display the string, paintString must be true.

See Also
setString, setStringPainted
uiClassIDback to summary
private static final String uiClassID

Hides javax.swing.JComponent.uiClassID.

See Also
getUIClassID

Constructor Detail

JProgressBarback to summary
public JProgressBar()

Creates a horizontal progress bar that displays a border but no progress string. The initial and minimum values are 0, and the maximum is 100.

See Also
setOrientation, setBorderPainted, setStringPainted, setString, setIndeterminate
JProgressBarback to summary
public JProgressBar(int orient)

Creates a progress bar with the specified orientation, which can be either SwingConstants.VERTICAL or SwingConstants.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.

Parameters
orient:int

the desired orientation of the progress bar

Exceptions
IllegalArgumentException:
if orient is an illegal value
See Also
setOrientation, setBorderPainted, setStringPainted, setString, setIndeterminate
JProgressBarback to summary
public JProgressBar(int min, int max)

Creates a horizontal progress bar with the specified minimum and maximum. Sets the initial value of the progress bar to the specified minimum. By default, a border is painted but a progress string is not.

The 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. See the BoundedRangeModel documentation for details.

Parameters
min:int

the minimum value of the progress bar

max:int

the maximum value of the progress bar

See Also
BoundedRangeModel, setOrientation, setBorderPainted, setStringPainted, setString, setIndeterminate
JProgressBarback to summary
public JProgressBar(int orient, int min, int max)

Creates a progress bar using the specified orientation, minimum, and maximum. By default, a border is painted but a progress string is not. Sets the initial value of the progress bar to the specified minimum.

The 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. See the BoundedRangeModel documentation for details.

Parameters
orient:int

the desired orientation of the progress bar

min:int

the minimum value of the progress bar

max:int

the maximum value of the progress bar

Exceptions
IllegalArgumentException:
if orient is an illegal value
See Also
BoundedRangeModel, setOrientation, setBorderPainted, setStringPainted, setString, setIndeterminate
JProgressBarback to summary
public JProgressBar(BoundedRangeModel newModel)

Creates a horizontal progress bar that uses the specified model to hold the progress bar's data. By default, a border is painted but a progress string is not.

Parameters
newModel:BoundedRangeModel

the data model for the progress bar

See Also
setOrientation, setBorderPainted, setStringPainted, setString, setIndeterminate

Method Detail

addChangeListenerback to summary
public void addChangeListener(ChangeListener l)

Adds the specified ChangeListener to the progress bar.

Parameters
l:ChangeListener

the ChangeListener to add

createChangeListenerback to summary
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. The default ChangeListener simply calls the fireStateChanged method to forward ChangeEvents to the ChangeListeners that have been added directly to the progress bar.

Returns:ChangeListener

the instance of a custom ChangeListener implementation.

See Also
changeListener, fireStateChanged, javax.swing.event.ChangeListener, javax.swing.BoundedRangeModel
fireStateChangedback to summary
protected void fireStateChanged()

Send a ChangeEvent, whose source is this JProgressBar, to all ChangeListeners that have registered interest in ChangeEvents. This method is called each time a ChangeEvent is received from the model.

The event instance is created if necessary, and stored in changeEvent.

See Also
addChangeListener, EventListenerList
getAccessibleContextback to summary
public AccessibleContext getAccessibleContext()

Overrides java.awt.Component.getAccessibleContext.

Implements javax.accessibility.Accessible.getAccessibleContext.

Gets the AccessibleContext associated with this JProgressBar. For progress bars, the AccessibleContext takes the form of an AccessibleJProgressBar. A new AccessibleJProgressBar instance is created if necessary.

Returns:AccessibleContext

an AccessibleJProgressBar that serves as the AccessibleContext of this JProgressBar

Annotations
@BeanProperty
bound:false
expert:true
description:The AccessibleContext associated with this ProgressBar.
getChangeListenersback to summary
public ChangeListener[] getChangeListeners()

Returns an array of all the ChangeListeners added to this progress bar with addChangeListener.

Returns:ChangeListener[]

all of the ChangeListeners added or an empty array if no listeners have been added

Annotations
@BeanProperty
bound:false
Since
1.4
getMaximumback to summary
public int getMaximum()

Returns the progress bar's maximum value from the BoundedRangeModel.

Returns:int

the progress bar's maximum value

See Also
setMaximum, BoundedRangeModel#getMaximum
getMinimumback to summary
public int getMinimum()

Returns the progress bar's minimum value from the BoundedRangeModel.

Returns:int

the progress bar's minimum value

See Also
setMinimum, BoundedRangeModel#getMinimum
getModelback to summary
public BoundedRangeModel getModel()

Returns the data model used by this progress bar.

Returns:BoundedRangeModel

the BoundedRangeModel currently in use

See Also
setModel, BoundedRangeModel
getOrientationback to summary
public int getOrientation()

Returns SwingConstants.VERTICAL or SwingConstants.HORIZONTAL, depending on the orientation of the progress bar. The default orientation is SwingConstants.HORIZONTAL.

Returns:int

HORIZONTAL or VERTICAL

See Also
setOrientation
getPercentCompleteback to summary
public double getPercentComplete()

Returns the percent complete for the progress bar. Note that this number is between 0.0 and 1.0.

Returns:double

the percent complete for this progress bar

Annotations
@BeanProperty
bound:false
getStringback to summary
public String getString()

Returns a String representation of the current progress. By default, this returns a simple percentage String based on the value returned from getPercentComplete. An example would be the "42%". You can change this by calling setString.

Returns:String

the value of the progress string, or a simple percentage string if the progress string is null

See Also
setString
getUIback to summary
public ProgressBarUI getUI()

Overrides javax.swing.JComponent.getUI.

Returns the look-and-feel object that renders this component.

Returns:ProgressBarUI

the ProgressBarUI object that renders this component

getUIClassIDback to summary
public String getUIClassID()

Overrides javax.swing.JComponent.getUIClassID.

Returns the name of the look-and-feel class that renders this component.

Returns:String

the string "ProgressBarUI"

Annotations
@BeanProperty
bound:false
expert:true
description:A string that specifies the name of the look-and-feel class.
See Also
JComponent#getUIClassID, UIDefaults#getUI
getValueback to summary
public int getValue()

Returns the progress bar's current value from the BoundedRangeModel. The value is always between the minimum and maximum values, inclusive.

Returns:int

the current value of the progress bar

See Also
setValue, BoundedRangeModel#getValue
isBorderPaintedback to summary
public boolean isBorderPainted()

Returns the borderPainted property.

Returns:boolean

the value of the borderPainted property

See Also
setBorderPainted
isIndeterminateback to summary
public boolean isIndeterminate()

Returns the value of the indeterminate property.

Returns:boolean

the value of the indeterminate property

Annotations
@BeanProperty
bound:false
description:Is the progress bar indeterminate (true) or normal (false)?
Since
1.4
See Also
setIndeterminate
isStringPaintedback to summary
public boolean isStringPainted()

Returns the value of the stringPainted property.

Returns:boolean

the value of the stringPainted property

See Also
setStringPainted, setString
paintBorderback to summary
protected void paintBorder(Graphics g)

Overrides javax.swing.JComponent.paintBorder.

Paints the progress bar's border if the borderPainted property is true.

Parameters
g:Graphics

the Graphics context within which to paint the border

See Also
paint, setBorder, isBorderPainted, setBorderPainted
paramStringback to summary
protected String paramString()

Overrides javax.swing.JComponent.paramString.

Returns a string representation of this 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.

Returns:String

a string representation of this JProgressBar

removeChangeListenerback to summary
public void removeChangeListener(ChangeListener l)

Removes a ChangeListener from the progress bar.

Parameters
l:ChangeListener

the ChangeListener to remove

setBorderPaintedback to summary
public void setBorderPainted(boolean b)

Sets the 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.

Parameters
b:boolean

true if the progress bar should paint its border; otherwise, false

Annotations
@BeanProperty
visualUpdate:true
description:Whether the progress bar should paint its border.
See Also
isBorderPainted
setIndeterminateback to summary
public void setIndeterminate(boolean newValue)

Sets the 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.

Parameters
newValue:boolean

true if the progress bar should change to indeterminate mode; false if it should revert to normal.

Since
1.4
See Also
isIndeterminate, javax.swing.plaf.basic.BasicProgressBarUI
setMaximumback to summary
public void setMaximum(int n)

Sets the progress bar's maximum value (stored in the progress bar's data model) to n.

The underlying BoundedRangeModel handles any mathematical issues arising from assigning faulty values. See the BoundedRangeModel documentation for details.

If the maximum value is different from the previous maximum, all change listeners are notified.

Parameters
n:int

the new maximum

Annotations
@BeanProperty
bound:false
preferred:true
description:The progress bar\'s maximum value.
See Also
getMaximum, addChangeListener, BoundedRangeModel#setMaximum
setMinimumback to summary
public void setMinimum(int n)

Sets the progress bar's minimum value (stored in the progress bar's data model) to n.

The data model (a BoundedRangeModel instance) handles any mathematical issues arising from assigning faulty values. See the BoundedRangeModel documentation for details.

If the minimum value is different from the previous minimum, all change listeners are notified.

Parameters
n:int

the new minimum

Annotations
@BeanProperty
bound:false
preferred:true
description:The progress bar\'s minimum value.
See Also
getMinimum, addChangeListener, BoundedRangeModel#setMinimum
setModelback to summary
public void setModel(BoundedRangeModel newModel)

Sets the data model used by the JProgressBar. Note that the BoundedRangeModel's extent is not used, and is set to 0.

Parameters
newModel:BoundedRangeModel

the BoundedRangeModel to use

Annotations
@BeanProperty
bound:false
expert:true
description:The data model used by the JProgressBar.
setOrientationback to summary
public void setOrientation(int newOrientation)

Sets the progress bar's orientation to newOrientation, which must be SwingConstants.VERTICAL or SwingConstants.HORIZONTAL. The default orientation is SwingConstants.HORIZONTAL.

Parameters
newOrientation:int

HORIZONTAL or VERTICAL

Annotations
@BeanProperty
preferred:true
visualUpdate:true
description:Set the progress bar\'s orientation.
Exceptions
IllegalArgumentException:
if newOrientation is an illegal value
See Also
getOrientation
setStringback to summary
public void setString(String s)

Sets the value of the progress string. By default, this string is null, implying the built-in behavior of using a simple percent string. If you have provided a custom progress string and want to revert to the built-in behavior, set the string back to null.

The progress string is painted only if the isStringPainted method returns true.

Parameters
s:String

the value of the progress string

Annotations
@BeanProperty
visualUpdate:true
description:Specifies the progress string to paint
See Also
getString, setStringPainted, isStringPainted
setStringPaintedback to summary
public void setStringPainted(boolean b)

Sets the value of the stringPainted property, which determines whether the progress bar should render a progress string. The default is false, meaning 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.

Parameters
b:boolean

true if the progress bar should render a string

Annotations
@BeanProperty
visualUpdate:true
description:Whether the progress bar should render a string.
See Also
isStringPainted, setString
setUIback to summary
public void setUI(ProgressBarUI ui)

Sets the look-and-feel object that renders this component.

Parameters
ui:ProgressBarUI

a ProgressBarUI object

Annotations
@BeanProperty
hidden:true
visualUpdate:true
description:The UI object that implements the Component\'s LookAndFeel.
See Also
UIDefaults#getUI
setValueback to summary
public void setValue(int n)

Sets the progress bar's current value to n. This method forwards the new value to the model.

The data model (an instance of BoundedRangeModel) handles any mathematical issues arising from assigning faulty values. See the BoundedRangeModel documentation for details.

If the new value is different from the previous value, all change listeners are notified.

Parameters
n:int

the new value

Annotations
@BeanProperty
bound:false
preferred:true
description:The progress bar\'s current value.
See Also
getValue, addChangeListener, BoundedRangeModel#setValue
updateUIback to summary
public void updateUI()

Overrides javax.swing.JComponent.updateUI.

Resets the UI property to a value from the current look and feel.

See Also
JComponent#updateUI
writeObjectback to summary
private void writeObject(ObjectOutputStream s) throws IOException

Hides javax.swing.JComponent.writeObject.

See readObject() and writeObject() in JComponent for more information about serialization in Swing.

Parameters
s:ObjectOutputStream

Doc from javax.swing.JComponent.writeObject.

the ObjectOutputStream in which to write

Annotations
@Serial
Exceptions
IOException:

Doc from java.awt.Container.writeObject.

if an I/O error occurs

javax.swing back to summary

protected Class JProgressBar.AccessibleJProgressBar

extends AccessibleJComponent
implements AccessibleValue
Class Inheritance
All Implemented Interfaces
javax.accessibility.AccessibleValue
Annotations
@SuppressWarnings:serial

This class implements accessibility support for the JProgressBar class. It provides an implementation of the Java Accessibility API appropriate to progress bar user-interface elements.

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 JavaBeans has been added to the java.beans package. Please see java.beans.XMLEncoder.

Field Summary

Inherited from javax.swing.JComponent.AccessibleJComponent:
accessibleFocusHandler

Constructor Summary

AccessConstructor and Description
protected
AccessibleJProgressBar()

Constructs an AccessibleJProgressBar.

Method Summary

Modifier and TypeMethod and Description
public AccessibleRole

Returns:

an instance of AccessibleRole describing the role of the object
getAccessibleRole
()

Overrides javax.swing.JComponent.AccessibleJComponent.getAccessibleRole.

Gets the role of this object.
public AccessibleStateSet

Returns:

an instance of AccessibleState containing the current state of the object
getAccessibleStateSet
()

Overrides javax.swing.JComponent.AccessibleJComponent.getAccessibleStateSet.

Gets the state set of this object.
public AccessibleValue

Returns:

this object
getAccessibleValue
()

Overrides javax.accessibility.AccessibleContext.getAccessibleValue.

Gets the AccessibleValue associated with this object.
public Number

Returns:

the current value of this object
getCurrentAccessibleValue
()

Implements javax.accessibility.AccessibleValue.getCurrentAccessibleValue.

Gets the accessible value of this object.
public Number

Returns:

the maximum value of this object
getMaximumAccessibleValue
()

Implements javax.accessibility.AccessibleValue.getMaximumAccessibleValue.

Gets the maximum accessible value of this object.
public Number

Returns:

the minimum value of this object
getMinimumAccessibleValue
()

Implements javax.accessibility.AccessibleValue.getMinimumAccessibleValue.

Gets the minimum accessible value of this object.
public boolean

Returns:

true if the value was set
setCurrentAccessibleValue
(Number
the number to use for the value
n
)

Implements javax.accessibility.AccessibleValue.setCurrentAccessibleValue.

Sets the value of this object as a Number.
Inherited from javax.swing.JComponent.AccessibleJComponent:
addPropertyChangeListenergetAccessibleChildgetAccessibleChildrenCountgetAccessibleDescriptiongetAccessibleExtendedComponentgetAccessibleKeyBindinggetAccessibleNamegetBorderTitlegetTitledBorderTextgetToolTipTextremovePropertyChangeListener

Constructor Detail

AccessibleJProgressBarback to summary
protected AccessibleJProgressBar()

Constructs an AccessibleJProgressBar.

Method Detail

getAccessibleRoleback to summary
public AccessibleRole getAccessibleRole()

Overrides javax.swing.JComponent.AccessibleJComponent.getAccessibleRole.

Gets the role of this object.

Returns:AccessibleRole

an instance of AccessibleRole describing the role of the object

getAccessibleStateSetback to summary
public AccessibleStateSet getAccessibleStateSet()

Overrides javax.swing.JComponent.AccessibleJComponent.getAccessibleStateSet.

Gets the state set of this object.

Returns:AccessibleStateSet

an instance of AccessibleState containing the current state of the object

See Also
AccessibleState
getAccessibleValueback to summary
public AccessibleValue getAccessibleValue()

Overrides javax.accessibility.AccessibleContext.getAccessibleValue.

Gets the AccessibleValue associated with this object. In the implementation of the Java Accessibility API for this class, returns this object, which is responsible for implementing the AccessibleValue interface on behalf of itself.

Returns:AccessibleValue

this object

getCurrentAccessibleValueback to summary
public Number getCurrentAccessibleValue()

Implements javax.accessibility.AccessibleValue.getCurrentAccessibleValue.

Gets the accessible value of this object.

Returns:Number

the current value of this object

getMaximumAccessibleValueback to summary
public Number getMaximumAccessibleValue()

Implements javax.accessibility.AccessibleValue.getMaximumAccessibleValue.

Gets the maximum accessible value of this object.

Returns:Number

the maximum value of this object

getMinimumAccessibleValueback to summary
public Number getMinimumAccessibleValue()

Implements javax.accessibility.AccessibleValue.getMinimumAccessibleValue.

Gets the minimum accessible value of this object.

Returns:Number

the minimum value of this object

setCurrentAccessibleValueback to summary
public boolean setCurrentAccessibleValue(Number n)

Implements javax.accessibility.AccessibleValue.setCurrentAccessibleValue.

Sets the value of this object as a Number.

Parameters
n:Number

Doc from javax.accessibility.AccessibleValue.setCurrentAccessibleValue.

the number to use for the value

Returns:boolean

true if the value was set

javax.swing back to summary

private Class JProgressBar.ModelListener

extends Object
implements ChangeListener, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, javax.swing.event.ChangeListener, java.util.EventListener
Annotations
@SuppressWarnings:serial

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
stateChanged(ChangeEvent
a ChangeEvent object
e
)

Implements javax.swing.event.ChangeListener.stateChanged.

Invoked when the target of the listener has changed its state.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ModelListenerback to summary
private ModelListener()

Method Detail

stateChangedback to summary
public void stateChanged(ChangeEvent e)

Implements javax.swing.event.ChangeListener.stateChanged.

Doc from javax.swing.event.ChangeListener.stateChanged.

Invoked when the target of the listener has changed its state.

Parameters
e:ChangeEvent

a ChangeEvent object