JavaTM 2 Platform
Std. Ed. v1.3.1

javax.swing
Class JProgressBar

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JProgressBar
All Implemented Interfaces:
Accessible, ImageObserver, MenuContainer, Serializable, SwingConstants

public class JProgressBar
extends JComponent
implements SwingConstants, Accessible

A component that displays an integer value within a bounded interval. A progress bar typically communicates the progress of an event by displaying its percentage of completion and possibly a textual display of this percentage.

For further documentation and examples see How 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. A future release of Swing will provide support for long term persistence.

See Also:
Serialized Form

Inner Class Summary
protected  class JProgressBar.AccessibleJProgressBar
          This class implements accessibility support for the JProgressBar class.
 
Inner classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Inner classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
Component.AccessibleAWTComponent
 
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
           
protected  BoundedRangeModel model
          The data structure that holds the various values for the progress bar.
protected  int orientation
          The orientation to display the progress bar.
protected  boolean paintBorder
          Whether to display the border around the progress bar.
protected  boolean paintString
          Whether to textually display a String on the progress bar.
protected  String progressString
          A 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, NORTH, NORTH_EAST, NORTH_WEST, 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.
JProgressBar(BoundedRangeModel newModel)
          Creates a horizontal progress bar, the default orientation.
JProgressBar(int orient)
          Creates a progress bar with the specified orientation, which can be either JProgressBar.VERTICAL or JProgressBar.HORIZONTAL.
JProgressBar(int min, int max)
          Creates a horizontal progress bar, which is the default.
JProgressBar(int orient, int min, int max)
          Creates a progress bar using the specified orientation, minimum, and maximum.
 
Method Summary
 void addChangeListener(ChangeListener l)
          Adds a ChangeListener to the button.
protected  ChangeListener createChangeListener()
           
protected  void fireStateChanged()
          Notify all listeners that have registered interest for notification on this event type.
 AccessibleContext getAccessibleContext()
          Gets the AccessibleContext associated with this JProgressBar.
 int getMaximum()
          Returns the model's maximum value.
 int getMinimum()
          Returns the model's minimum value.
 BoundedRangeModel getModel()
          Returns the data model used by the JProgressBar.
 int getOrientation()
          Returns JProgressBar.VERTICAL or JProgressBar.HORIZONTAL, depending on the orientation of the progress bar.
 double getPercentComplete()
          Returns the percentage/percent complete for the progress bar.
 String getString()
          Returns the current value of the Progress String.
 ProgressBarUI getUI()
          Returns the L&F object that renders this component.
 String getUIClassID()
          Returns the name of the L&F class that renders this component.
 int getValue()
          Returns the model's current value.
 boolean isBorderPainted()
          Returns true if the progress bar has a border or false if it does not.
 boolean isStringPainted()
          Returns true if the progress bar will render a string onto the representation of the progress bar.
protected  void paintBorder(Graphics g)
          Paint the progress bar's border if BorderPainted property is true.
protected  String paramString()
          Returns a string representation of this JProgressBar.
 void removeChangeListener(ChangeListener l)
          Removes a ChangeListener from the button.
 void setBorderPainted(boolean b)
          Sets whether the progress bar should paint its border.
 void setMaximum(int n)
          Sets the model's maximum to x.
 void setMinimum(int n)
          Sets the model's minimum to x.
 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 whether the progress bar will render a string.
 void setUI(ProgressBarUI ui)
          Sets the L&F object that renders this component.
 void setValue(int n)
          Sets the model's current value to x.
 void updateUI()
          Notification from the UIFactory that the L&F has changed.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVerifyInputWhenFocusTarget, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, hide, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processFocusEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

orientation

protected int orientation
The orientation to display the progress bar. The default is HORIZONTAL.

paintBorder

protected boolean paintBorder
Whether to display the border around the progress bar. The default is true.

model

protected BoundedRangeModel model
The data structure that holds the various values for the progress bar.

progressString

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

paintString

protected boolean paintString
Whether to textually display a String on the progress bar. The default is false. Setting this to true will cause a textual display of the progress to de rendered on the progress bar. If the progressString is null, the percentage done to be displayed on the progress bar. If the progressString is non-null, it is rendered on the progress bar.

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
Constructor Detail

JProgressBar

public JProgressBar()
Creates a horizontal progress bar. The default orientation for progress bars is JProgressBar.HORIZONTAL. By default, the String is set to null and the StringPainted is not painted. The border is painted by default. Uses the defaultMinimum (0) and defaultMaximum (100). Uses the defaultMinimum for the initial value of the progress bar.

JProgressBar

public JProgressBar(int orient)
Creates a progress bar with the specified orientation, which can be either JProgressBar.VERTICAL or JProgressBar.HORIZONTAL. By default, the String is set to null and the StringPainted is not painted. The border is painted by default. Uses the defaultMinimum (0) and defaultMaximum (100). Uses the defaultMinimum for the initial value of the progress bar.

JProgressBar

public JProgressBar(int min,
                    int max)
Creates a horizontal progress bar, which is the default. By default, the String is set to null and the StringPainted is not painted. The border is painted by default. Uses the specified minimum and maximum. Uses the specified minimum for the initial value of the progress bar.

JProgressBar

public JProgressBar(int orient,
                    int min,
                    int max)
Creates a progress bar using the specified orientation, minimum, and maximum. By default, the String is set to null and the StringPainted is not painted. The border is painted by default. Sets the inital value of the progress bar to the specified minimum. The BoundedRangeModel that sits underneath the progress bar handles any issues that may arrise from improperly setting the minimum, value, and maximum on the progress bar.
See Also:
BoundedRangeModel, setOrientation(int), setBorderPainted(boolean), setStringPainted(boolean), setString(java.lang.String)

JProgressBar

public JProgressBar(BoundedRangeModel newModel)
Creates a horizontal progress bar, the default orientation. By default, the String is set to null and the StringPainted is not painted. The border is painted by default. Uses the specified BoundedRangeModel which holds the minimum, value, and maximum.
See Also:
BoundedRangeModel, setOrientation(int), setBorderPainted(boolean), setStringPainted(boolean), setString(java.lang.String)
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 - if newOrientation is an illegal value
See Also:
getOrientation()

isStringPainted

public boolean isStringPainted()
Returns true if the progress bar will render a string onto the representation of the progress bar. Returns false if it will not do this rendering. The default is false - the progress bar does not draw the string by default.
Returns:
whether the progress bar renders a string
See Also:
setStringPainted(boolean), setString(java.lang.String)

setStringPainted

public void setStringPainted(boolean b)
Sets whether the progress bar will render a string.
Parameters:
b - true if the progress bar will render a string.
See Also:
isStringPainted()

getString

public String getString()
Returns the current value of the Progress String. If you are providing a custom Progress String via this method, you will want to ensure that you call setString() before you call 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 set to null. If you are providing a custom Progress String via this method, you will want to ensure that you call setString() before you call getString(). If you have provided a custom String and want to revert to the built-in behavior, set the String back to null.
Parameters:
s - the value of the percent string
See Also:
getString()

getPercentComplete

public double getPercentComplete()
Returns the percentage/percent complete for the progress bar. Note that, as a double, this number is between 0.00 and 1.00.
Returns:
the percent complete for this progress bar.

isBorderPainted

public boolean isBorderPainted()
Returns true if the progress bar has a border or false if it does not. By default, this is true - the progress bar paints it's border.
Returns:
whether the progress bar paints its border
See Also:
setBorderPainted(boolean)

setBorderPainted

public void setBorderPainted(boolean b)
Sets whether the progress bar should paint its border. By default, this is true - paint the border.
Parameters:
b - true if the progress bar paints its border
See Also:
isBorderPainted()

paintBorder

protected void paintBorder(Graphics g)
Paint the progress bar's border if BorderPainted property is true.
Overrides:
paintBorder in class JComponent
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 L&F object that renders this component.
Returns:
the ProgressBarUI object that renders this component

setUI

public void setUI(ProgressBarUI ui)
Sets the L&F object that renders this component.
Parameters:
ui - the ProgressBarUI L&F object
See Also:
UIDefaults.getUI(javax.swing.JComponent)

updateUI

public void updateUI()
Notification from the UIFactory that the L&F has changed. Called to replace the UI with the latest version from the UIFactory.
Overrides:
updateUI in class JComponent
See Also:
JComponent.updateUI()

getUIClassID

public String getUIClassID()
Returns the name of the L&F class that renders this component.
Overrides:
getUIClassID in class JComponent
Returns:
"ProgressBarUI"
See Also:
JComponent.getUIClassID(), UIDefaults.getUI(javax.swing.JComponent)

createChangeListener

protected ChangeListener createChangeListener()

addChangeListener

public void addChangeListener(ChangeListener l)
Adds a ChangeListener to the button.
Parameters:
l - the ChangeListener to add

removeChangeListener

public void removeChangeListener(ChangeListener l)
Removes a ChangeListener from the button.
Parameters:
l - the ChangeListener to remove

fireStateChanged

protected void fireStateChanged()
Notify all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.
See Also:
EventListenerList

getModel

public BoundedRangeModel getModel()
Returns the data model used by the JProgressBar.
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
See Also:
BoundedRangeModel

getValue

public int getValue()
Returns the model's current value. The value is always between the model's minimum and maximum values, inclusive. By default, the value equals the minimum.
Returns:
the value
See Also:
setValue(int), BoundedRangeModel

getMinimum

public int getMinimum()
Returns the model's minimum value. By default, this is 0.
Returns:
an int -- the model's minimum
See Also:
setMinimum(int), BoundedRangeModel

getMaximum

public int getMaximum()
Returns the model's maximum value. By default, this is 100.
Returns:
an int -- the model's maximum
See Also:
setMaximum(int), BoundedRangeModel

setValue

public void setValue(int n)
Sets the model's current value to x. The underlying BoundedRangeModel will handle any mathematical issues arrising from assigning faulty values.
Parameters:
x - the new value
See Also:
getValue(), BoundedRangeModel.setValue(int)

setMinimum

public void setMinimum(int n)
Sets the model's minimum to x. The underlying BoundedRangeModel will handle any mathematical issues arrising from assigning faulty values.

Notifies any listeners if the data changes.

Parameters:
x - the new minimum
See Also:
getMinimum(), addChangeListener(javax.swing.event.ChangeListener), BoundedRangeModel

setMaximum

public void setMaximum(int n)
Sets the model's maximum to x. The underlying BoundedRangeModel will handle any mathematical issues arrising from assigning faulty values.

Notifies any listeners if the data changes.

Parameters:
x - the new maximum
See Also:
getMaximum(), addChangeListener(javax.swing.event.ChangeListener), BoundedRangeModel

paramString

protected String paramString()
Returns a string representation of this JProgressBar. This method is intended to be used only for debugging purposes, and 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 in class JComponent
Returns:
a string representation of this JProgressBar.

getAccessibleContext

public 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.
Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in class JComponent
Returns:
an AccessibleJProgressBar that serves as the AccessibleContext of this JProgressBar

JavaTM 2 Platform
Std. Ed. v1.3.1

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.

Java, Java 2D, and JDBC are trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-2001 Sun Microsystems, Inc. 901 San Antonio Road
Palo Alto, California, 94303, U.S.A. All Rights Reserved.



Spec-Zone.ru - all specs in one place



free hit counter