JProgressBar (Java 2 Platform SE 5.0) (original) (raw)


javax.swing

Class JProgressBar

java.lang.Object extended by java.awt.Component extended by java.awt.Container extended by javax.swing.JComponent extended by javax.swing.JProgressBar

All Implemented Interfaces:

ImageObserver, MenuContainer, Serializable, Accessible, SwingConstants


public class JProgressBar

extends JComponent

implements SwingConstants, Accessible

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 seeHow 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 XMLEncoder.

See Also:

BasicProgressBarUI


Nested Class Summary
protected class JProgressBar.AccessibleJProgressBar This class implements accessibility support for the JProgressBar 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 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.
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.
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 horizontal progress bar that displays a border but no progress string.
JProgressBar(BoundedRangeModel newModel) Creates a horizontal progress bar that uses the specified model to hold the progress bar's data.
JProgressBar(int orient) Creates a progress bar with the specified orientation, which can be either JProgressBar.VERTICAL or JProgressBar.HORIZONTAL.
[JProgressBar](../../javax/swing/JProgressBar.html#JProgressBar%28int, int%29)(int min, int max) Creates a horizontal progress bar with the specified minimum and maximum.
[JProgressBar](../../javax/swing/JProgressBar.html#JProgressBar%28int, int, int%29)(int orient, int min, int max) Creates a progress bar using the specified orientation, minimum, and maximum.
Method Summary
void addChangeListener(ChangeListener l) 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 inChangeEvents.
AccessibleContext getAccessibleContext() Gets the AccessibleContext associated with this JProgressBar.
ChangeListener[] getChangeListeners() Returns an array of all the ChangeListeners added to this progress bar with addChangeListener.
int getMaximum() Returns the progress bar's maximum value, which is stored in the progress bar's BoundedRangeModel.
int getMinimum() Returns the progress bar's minimum value, which is stored in the progress bar's BoundedRangeModel.
BoundedRangeModel getModel() Returns the data model used by this progress bar.
int getOrientation() Returns JProgressBar.VERTICAL or JProgressBar.HORIZONTAL, depending on the orientation of the progress bar.
double getPercentComplete() Returns the percent complete for the progress bar.
String getString() Returns the current value of the progress string.
ProgressBarUI getUI() Returns the look-and-feel object that renders this component.
String getUIClassID() Returns the name of the look-and-feel class that renders this component.
int getValue() Returns the progress bar's current value, which is stored in the progress bar's BoundedRangeModel.
boolean isBorderPainted() Returns the borderPainted property.
boolean isIndeterminate() Returns the value of the indeterminate property.
boolean isStringPainted() 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) Removes a ChangeListener from the progress bar.
void setBorderPainted(boolean b) Sets the borderPainted property, which istrue if the progress bar should paint its border.
void setIndeterminate(boolean newValue) Sets the indeterminate property of the progress bar, which determines whether the progress bar is in determinate or indeterminate mode.
void setMaximum(int n) Sets the progress bar's maximum value (stored in the progress bar's data model) to n.
void setMinimum(int n) Sets the progress bar's minimum value (stored in the progress bar's data model) to n.
void setModel(BoundedRangeModel newModel) Sets the data model used by the JProgressBar.
void setOrientation(int newOrientation) Sets the progress bar's orientation to newOrientation, which must be JProgressBar.VERTICAL or JProgressBar.HORIZONTAL.
void setString(String s) Sets the value of the progress string.
void setStringPainted(boolean b) Sets the value of the stringPainted property, which determines whether the progress bar should render a progress string.
void setUI(ProgressBarUI ui) Sets the look-and-feel object that renders this component.
void setValue(int n) Sets the progress bar's current value (stored in the progress bar's data model) to n.
void updateUI() Resets the UI property to a value from the current look and feel.
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, [contains](../../javax/swing/JComponent.html#contains%28int, int%29), createToolTip, disable, enable, [firePropertyChange](../../javax/swing/JComponent.html#firePropertyChange%28java.lang.String, boolean, boolean%29), [firePropertyChange](../../javax/swing/JComponent.html#firePropertyChange%28java.lang.String, char, char%29), [firePropertyChange](../../javax/swing/JComponent.html#firePropertyChange%28java.lang.String, int, int%29), [fireVetoableChange](../../javax/swing/JComponent.html#fireVetoableChange%28java.lang.String, java.lang.Object, java.lang.Object%29), getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintComponent, [paintImmediately](../../javax/swing/JComponent.html#paintImmediately%28int, int, int, int%29), paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, [processKeyBinding](../../javax/swing/JComponent.html#processKeyBinding%28javax.swing.KeyStroke, java.awt.event.KeyEvent, int, boolean%29), processKeyEvent, processMouseEvent, processMouseMotionEvent, [putClientProperty](../../javax/swing/JComponent.html#putClientProperty%28java.lang.Object, java.lang.Object%29), [registerKeyboardAction](../../javax/swing/JComponent.html#registerKeyboardAction%28java.awt.event.ActionListener, javax.swing.KeyStroke, int%29), [registerKeyboardAction](../../javax/swing/JComponent.html#registerKeyboardAction%28java.awt.event.ActionListener, java.lang.String, javax.swing.KeyStroke, int%29), removeAncestorListener, removeNotify, removeVetoableChangeListener, [repaint](../../javax/swing/JComponent.html#repaint%28long, int, int, int, int%29), repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, [reshape](../../javax/swing/JComponent.html#reshape%28int, int, int, int%29), revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, [setFocusTraversalKeys](../../javax/swing/JComponent.html#setFocusTraversalKeys%28int, java.util.Set%29), setFont, setForeground, setInheritsPopupMenu, [setInputMap](../../javax/swing/JComponent.html#setInputMap%28int, javax.swing.InputMap%29), setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
Methods inherited from class java.awt.Container
add, [add](../../java/awt/Container.html#add%28java.awt.Component, int%29), [add](../../java/awt/Container.html#add%28java.awt.Component, java.lang.Object%29), [add](../../java/awt/Container.html#add%28java.awt.Component, java.lang.Object, int%29), [add](../../java/awt/Container.html#add%28java.lang.String, java.awt.Component%29), addContainerListener, [addImpl](../../java/awt/Container.html#addImpl%28java.awt.Component, java.lang.Object, int%29), addPropertyChangeListener, [addPropertyChangeListener](../../java/awt/Container.html#addPropertyChangeListener%28java.lang.String, java.beans.PropertyChangeListener%29), applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, [findComponentAt](../../java/awt/Container.html#findComponentAt%28int, int%29), findComponentAt, getComponent, [getComponentAt](../../java/awt/Container.html#getComponentAt%28int, int%29), getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, [list](../../java/awt/Container.html#list%28java.io.PrintStream, int%29), [list](../../java/awt/Container.html#list%28java.io.PrintWriter, int%29), [locate](../../java/awt/Container.html#locate%28int, int%29), minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, [setComponentZOrder](../../java/awt/Container.html#setComponentZOrder%28java.awt.Component, int%29), setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
Methods inherited from class java.awt.Component
[action](../../java/awt/Component.html#action%28java.awt.Event, java.lang.Object%29), add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, [checkImage](../../java/awt/Component.html#checkImage%28java.awt.Image, java.awt.image.ImageObserver%29), [checkImage](../../java/awt/Component.html#checkImage%28java.awt.Image, int, int, java.awt.image.ImageObserver%29), [coalesceEvents](../../java/awt/Component.html#coalesceEvents%28java.awt.AWTEvent, java.awt.AWTEvent%29), contains, createImage, [createImage](../../java/awt/Component.html#createImage%28int, int%29), [createVolatileImage](../../java/awt/Component.html#createVolatileImage%28int, int%29), [createVolatileImage](../../java/awt/Component.html#createVolatileImage%28int, int, java.awt.ImageCapabilities%29), disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, byte, byte%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, double, double%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, float, float%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, long, long%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, java.lang.Object, java.lang.Object%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, short, short%29), getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, [gotFocus](../../java/awt/Component.html#gotFocus%28java.awt.Event, java.lang.Object%29), handleEvent, hasFocus, hide, [imageUpdate](../../java/awt/Component.html#imageUpdate%28java.awt.Image, int, int, int, int, int%29), [inside](../../java/awt/Component.html#inside%28int, int%29), isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, [keyDown](../../java/awt/Component.html#keyDown%28java.awt.Event, int%29), [keyUp](../../java/awt/Component.html#keyUp%28java.awt.Event, int%29), list, list, list, location, [lostFocus](../../java/awt/Component.html#lostFocus%28java.awt.Event, java.lang.Object%29), [mouseDown](../../java/awt/Component.html#mouseDown%28java.awt.Event, int, int%29), [mouseDrag](../../java/awt/Component.html#mouseDrag%28java.awt.Event, int, int%29), [mouseEnter](../../java/awt/Component.html#mouseEnter%28java.awt.Event, int, int%29), [mouseExit](../../java/awt/Component.html#mouseExit%28java.awt.Event, int, int%29), [mouseMove](../../java/awt/Component.html#mouseMove%28java.awt.Event, int, int%29), [mouseUp](../../java/awt/Component.html#mouseUp%28java.awt.Event, int, int%29), [move](../../java/awt/Component.html#move%28int, int%29), nextFocus, paintAll, postEvent, [prepareImage](../../java/awt/Component.html#prepareImage%28java.awt.Image, java.awt.image.ImageObserver%29), [prepareImage](../../java/awt/Component.html#prepareImage%28java.awt.Image, int, int, java.awt.image.ImageObserver%29), processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, [removePropertyChangeListener](../../java/awt/Component.html#removePropertyChangeListener%28java.lang.String, java.beans.PropertyChangeListener%29), repaint, [repaint](../../java/awt/Component.html#repaint%28int, int, int, int%29), repaint, resize, [resize](../../java/awt/Component.html#resize%28int, int%29), [setBounds](../../java/awt/Component.html#setBounds%28int, int, int, int%29), setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, [setLocation](../../java/awt/Component.html#setLocation%28int, int%29), setLocation, setName, setSize, [setSize](../../java/awt/Component.html#setSize%28int, int%29), show, show, size, toString, transferFocus, transferFocusUpCycle
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, [wait](../../java/lang/Object.html#wait%28long, int%29)
Field Detail

orientation

protected int orientation

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

See Also:

setOrientation(int)


paintBorder

protected boolean paintBorder

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

See Also:

setBorderPainted(boolean)


model

protected BoundedRangeModel model

The object that holds the data for the progress bar.

See Also:

setModel(javax.swing.BoundedRangeModel)


progressString

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.

See Also:

setString(java.lang.String)


paintString

protected boolean paintString

Whether to textually display a string 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(boolean)


changeEvent

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.


changeListener

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()

Constructor Detail

JProgressBar

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(int), setBorderPainted(boolean), setStringPainted(boolean), setString(java.lang.String), setIndeterminate(boolean)


JProgressBar

public JProgressBar(int orient)

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

Parameters:

orient - the desired orientation of the progress bar

See Also:

setOrientation(int), setBorderPainted(boolean), setStringPainted(boolean), setString(java.lang.String), setIndeterminate(boolean)


JProgressBar

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.

Parameters:

min - the minimum value of the progress bar

max - the maximum value of the progress bar

See Also:

BoundedRangeModel, setOrientation(int), setBorderPainted(boolean), setStringPainted(boolean), setString(java.lang.String), setIndeterminate(boolean)


JProgressBar

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.

Parameters:

orient - the desired orientation of the progress bar

min - the minimum value of the progress bar

max - the maximum value of the progress bar

See Also:

BoundedRangeModel, setOrientation(int), setBorderPainted(boolean), setStringPainted(boolean), setString(java.lang.String), setIndeterminate(boolean)


JProgressBar

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 - the data model for the progress bar

See Also:

setOrientation(int), setBorderPainted(boolean), setStringPainted(boolean), setString(java.lang.String), setIndeterminate(boolean)

Method Detail

getOrientation

public int getOrientation()

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

Returns:

HORIZONTAL or VERTICAL

See Also:

setOrientation(int)


setOrientation

public void setOrientation(int newOrientation)

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

Parameters:

newOrientation - HORIZONTAL or VERTICAL

Throws:

[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang") - if newOrientation is an illegal value

See Also:

getOrientation()


isStringPainted

public boolean isStringPainted()

Returns the value of the stringPainted property.

Returns:

the value of the stringPainted property

See Also:

setStringPainted(boolean), setString(java.lang.String)


setStringPainted

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: 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 - true if the progress bar should render a string

See Also:

isStringPainted(), setString(java.lang.String)


getString

public String getString()

Returns the current value of the progress string. If you are providing a custom progress string by overriding this method, make sure your implementation calls setString before calling super.getString.

Returns:

the value of the percent string

See Also:

setString(java.lang.String)


setString

public void setString(String s)

Sets the value of the progress string. By default, this string is 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.

Parameters:

s - the value of the percent string

See Also:

getString(), setStringPainted(boolean), isStringPainted()


getPercentComplete

public double getPercentComplete()

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

Returns:

the percent complete for this progress bar


isBorderPainted

public boolean isBorderPainted()

Returns the borderPainted property.

Returns:

the value of the borderPainted property

See Also:

setBorderPainted(boolean)


setBorderPainted

public void setBorderPainted(boolean b)

Sets the borderPainted property, which istrue 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 - true if the progress bar should paint its border; otherwise, false

See Also:

isBorderPainted()


paintBorder

protected void paintBorder(Graphics g)

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

Overrides:

[paintBorder](../../javax/swing/JComponent.html#paintBorder%28java.awt.Graphics%29) in class [JComponent](../../javax/swing/JComponent.html "class in javax.swing")

Parameters:

g - the Graphics context within which to paint the border

See Also:

JComponent.paint(java.awt.Graphics), JComponent.setBorder(javax.swing.border.Border), isBorderPainted(), setBorderPainted(boolean)


getUI

public ProgressBarUI getUI()

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

Returns:

the ProgressBarUI object that renders this component


setUI

public void setUI(ProgressBarUI ui)

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

Parameters:

ui - a ProgressBarUI object

See Also:

UIDefaults.getUI(javax.swing.JComponent)


updateUI

public void updateUI()

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

Overrides:

[updateUI](../../javax/swing/JComponent.html#updateUI%28%29) in class [JComponent](../../javax/swing/JComponent.html "class in javax.swing")

See Also:

JComponent.updateUI()


getUIClassID

public String getUIClassID()

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

Overrides:

[getUIClassID](../../javax/swing/JComponent.html#getUIClassID%28%29) in class [JComponent](../../javax/swing/JComponent.html "class in javax.swing")

Returns:

the string "ProgressBarUI"

See Also:

JComponent.getUIClassID(), UIDefaults.getUI(javax.swing.JComponent)


createChangeListener

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.

See Also:

changeListener, ChangeListener, BoundedRangeModel


addChangeListener

public void addChangeListener(ChangeListener l)

Adds the specified ChangeListener to the progress bar.

Parameters:

l - the ChangeListener to add


removeChangeListener

public void removeChangeListener(ChangeListener l)

Removes a ChangeListener from the progress bar.

Parameters:

l - the ChangeListener to remove


getChangeListeners

public ChangeListener[] getChangeListeners()

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

Returns:

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

Since:

1.4


fireStateChanged

protected void fireStateChanged()

Notifies all listeners that have registered interest inChangeEvents. The event instance is created if necessary.

See Also:

EventListenerList


getModel

public BoundedRangeModel getModel()

Returns the data model used by this progress bar.

Returns:

the BoundedRangeModel currently in use

See Also:

BoundedRangeModel


setModel

public void setModel(BoundedRangeModel newModel)

Sets the data model used by the JProgressBar.

Parameters:

newModel - the BoundedRangeModel to use


getValue

public int getValue()

Returns the progress bar's current value, which is stored in the progress bar's 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.

Returns:

the current value of the progress bar

See Also:

setValue(int), BoundedRangeModel.getValue()


getMinimum

public int getMinimum()

Returns the progress bar's minimum value, which is stored in the progress bar's BoundedRangeModel. By default, the minimum value is 0.

Returns:

the progress bar's minimum value

See Also:

setMinimum(int), BoundedRangeModel.getMinimum()


getMaximum

public int getMaximum()

Returns the progress bar's maximum value, which is stored in the progress bar's BoundedRangeModel. By default, the maximum value is 100.

Returns:

the progress bar's maximum value

See Also:

setMaximum(int), BoundedRangeModel.getMaximum()


setValue

public void setValue(int n)

Sets the progress bar's current 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.

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

Parameters:

n - the new value

See Also:

getValue(), BoundedRangeModel.setValue(int)


setMinimum

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.

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

Parameters:

n - the new minimum

See Also:

getMinimum(), addChangeListener(javax.swing.event.ChangeListener), BoundedRangeModel.setMinimum(int)


setMaximum

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.

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

Parameters:

n - the new maximum

See Also:

getMaximum(), addChangeListener(javax.swing.event.ChangeListener), BoundedRangeModel.setMaximum(int)


setIndeterminate

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 - true if the progress bar should change to indeterminate mode;false if it should revert to normal.

Since:

1.4

See Also:

isIndeterminate(), BasicProgressBarUI


isIndeterminate

public boolean isIndeterminate()

Returns the value of the indeterminate property.

Returns:

the value of the indeterminate property

Since:

1.4

See Also:

setIndeterminate(boolean)


paramString

protected String 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.

Overrides:

[paramString](../../javax/swing/JComponent.html#paramString%28%29) in class [JComponent](../../javax/swing/JComponent.html "class in javax.swing")

Returns:

a string representation of this JProgressBar


getAccessibleContext

public AccessibleContext getAccessibleContext()

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

Specified by:

[getAccessibleContext](../../javax/accessibility/Accessible.html#getAccessibleContext%28%29) in interface [Accessible](../../javax/accessibility/Accessible.html "interface in javax.accessibility")

Overrides:

[getAccessibleContext](../../javax/swing/JComponent.html#getAccessibleContext%28%29) in class [JComponent](../../javax/swing/JComponent.html "class in javax.swing")

Returns:

an AccessibleJProgressBar that serves as the AccessibleContext of this JProgressBar



Submit a bug or feature
For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.

Copyright © 2004, 2010 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.