javax.swing
public class JProgressBar extends JComponent implements SwingConstants, Accessible
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 |
Modifier and Type | Class and Description |
---|---|
protected class |
JProgressBar.AccessibleJProgressBar
Provides the accessibility features for the
JProgressBar
component. |
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
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
|
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.
|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
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. |
Modifier and Type | Method and Description |
---|---|
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()
|
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. |
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, 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, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setNextFocusableComponent, setOpaque, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, 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, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
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
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).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
).