Methods Summary |
---|
public void | addChangeListener(javax.swing.event.ChangeListener l)Adds the specified ChangeListener to the progress bar.
listenerList.add(ChangeListener.class, l);
|
protected javax.swing.event.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.
return new ModelListener();
|
protected void | fireStateChanged()Notifies all listeners that have registered interest in
ChangeEvent s.
The event instance
is created if necessary.
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners[i]==ChangeListener.class) {
// Lazily create the event:
if (changeEvent == null)
changeEvent = new ChangeEvent(this);
((ChangeListener)listeners[i+1]).stateChanged(changeEvent);
}
}
|
public javax.accessibility.AccessibleContext | 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.
if (accessibleContext == null) {
accessibleContext = new AccessibleJProgressBar();
}
return accessibleContext;
|
public javax.swing.event.ChangeListener[] | getChangeListeners()Returns an array of all the ChangeListener s added
to this progress bar with addChangeListener .
return (ChangeListener[])listenerList.getListeners(
ChangeListener.class);
|
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 .
return getModel().getMaximum();
|
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 .
return getModel().getMinimum();
|
public javax.swing.BoundedRangeModel | getModel()Returns the data model used by this progress bar.
return model;
|
public int | getOrientation()Returns JProgressBar.VERTICAL or
JProgressBar.HORIZONTAL , depending on the orientation
of the progress bar. The default orientation is
HORIZONTAL .
return orientation;
|
public double | getPercentComplete()Returns the percent complete for the progress bar.
Note that this number is between 0.0 and 1.0.
long span = model.getMaximum() - model.getMinimum();
double currentValue = model.getValue();
double pc = (currentValue - model.getMinimum()) / span;
return pc;
|
public java.lang.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 .
if (progressString != null) {
return progressString;
} else {
if (format == null) {
format = NumberFormat.getPercentInstance();
}
return format.format(new Double(getPercentComplete()));
}
|
public javax.swing.plaf.ProgressBarUI | getUI()Returns the look-and-feel object that renders this component.
return (ProgressBarUI)ui;
|
public java.lang.String | getUIClassID()Returns the name of the look-and-feel class that renders this component.
return uiClassID;
|
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.
return getModel().getValue();
|
public boolean | isBorderPainted()Returns the borderPainted property.
return paintBorder;
|
public boolean | isIndeterminate()Returns the value of the indeterminate property.
return indeterminate;
|
public boolean | isStringPainted()Returns the value of the stringPainted property.
return paintString;
|
protected void | paintBorder(java.awt.Graphics g)Paints the progress bar's border if the borderPainted
property is true .
if (isBorderPainted()) {
super.paintBorder(g);
}
|
protected java.lang.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 .
String orientationString = (orientation == HORIZONTAL ?
"HORIZONTAL" : "VERTICAL");
String paintBorderString = (paintBorder ?
"true" : "false");
String progressStringString = (progressString != null ?
progressString : "");
String paintStringString = (paintString ?
"true" : "false");
String indeterminateString = (indeterminate ?
"true" : "false");
return super.paramString() +
",orientation=" + orientationString +
",paintBorder=" + paintBorderString +
",paintString=" + paintStringString +
",progressString=" + progressStringString +
",indeterminateString=" + indeterminateString;
|
public void | removeChangeListener(javax.swing.event.ChangeListener l)Removes a ChangeListener from the progress bar.
listenerList.remove(ChangeListener.class, l);
|
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.
boolean oldValue = paintBorder;
paintBorder = b;
firePropertyChange("borderPainted", oldValue, paintBorder);
if (paintBorder != oldValue) {
repaint();
}
|
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.
boolean oldValue = indeterminate;
indeterminate = newValue;
firePropertyChange("indeterminate", oldValue, indeterminate);
|
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.
getModel().setMaximum(n);
|
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.
getModel().setMinimum(n);
|
public void | setModel(javax.swing.BoundedRangeModel newModel)Sets the data model used by the JProgressBar .
// PENDING(???) setting the same model to multiple bars is broken; listeners
BoundedRangeModel oldModel = getModel();
if (newModel != oldModel) {
if (oldModel != null) {
oldModel.removeChangeListener(changeListener);
changeListener = null;
}
model = newModel;
if (newModel != null) {
changeListener = createChangeListener();
newModel.addChangeListener(changeListener);
}
if (accessibleContext != null) {
accessibleContext.firePropertyChange(
AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
(oldModel== null
? null : new Integer(oldModel.getValue())),
(newModel== null
? null : new Integer(newModel.getValue())));
}
if (model != null) {
model.setExtent(0);
}
repaint();
}
|
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 .
if (orientation != newOrientation) {
switch (newOrientation) {
case VERTICAL:
case HORIZONTAL:
int oldOrientation = orientation;
orientation = newOrientation;
firePropertyChange("orientation", oldOrientation, newOrientation);
if (accessibleContext != null) {
accessibleContext.firePropertyChange(
AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
((oldOrientation == VERTICAL)
? AccessibleState.VERTICAL
: AccessibleState.HORIZONTAL),
((orientation == VERTICAL)
? AccessibleState.VERTICAL
: AccessibleState.HORIZONTAL));
}
break;
default:
throw new IllegalArgumentException(newOrientation +
" is not a legal orientation");
}
revalidate();
}
|
public void | setString(java.lang.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 .
String oldValue = progressString;
progressString = s;
firePropertyChange("string", oldValue, progressString);
if (progressString == null || oldValue == null || !progressString.equals(oldValue)) {
repaint();
}
|
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.
//PENDING: specify that string not painted when in indeterminate mode?
// or just leave that to the L&F?
boolean oldValue = paintString;
paintString = b;
firePropertyChange("stringPainted", oldValue, paintString);
if (paintString != oldValue) {
revalidate();
repaint();
}
|
public void | setUI(javax.swing.plaf.ProgressBarUI ui)Sets the look-and-feel object that renders this component.
super.setUI(ui);
|
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.
BoundedRangeModel brm = getModel();
int oldValue = brm.getValue();
brm.setValue(n);
if (accessibleContext != null) {
accessibleContext.firePropertyChange(
AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
new Integer(oldValue),
new Integer(brm.getValue()));
}
|
public void | updateUI()Resets the UI property to a value from the current look and feel.
setUI((ProgressBarUI)UIManager.getUI(this));
|
private void | writeObject(java.io.ObjectOutputStream s)See readObject() and writeObject() in JComponent for more
information about serialization in Swing.
s.defaultWriteObject();
if (getUIClassID().equals(uiClassID)) {
byte count = JComponent.getWriteObjCounter(this);
JComponent.setWriteObjCounter(this, --count);
if (count == 0 && ui != null) {
ui.installUI(this);
}
}
|