所有类


javax.swing
类 JProgressBar

java.lang.Object
  继承者 java.awt.Component
      继承者 java.awt.Container
          继承者 javax.swing.JComponent
              继承者 javax.swing.JProgressBar
所有已实现的接口:
ImageObserver, MenuContainer, Serializable, Accessible, SwingConstants

public class JProgressBar
   
   
   
   
extends JComponent
implements SwingConstants, Accessible

默认显示有界区间整数值的组件。进度条通常通过显示某个操作的完成百分比,可能是此百分比的一个文本显示来传达其进度。

要指示正在执行一个未知长度的任务,可以将进度条设置为不确定模式。不确定模式的进度条持续地显示动画来表示正进行的操作。一旦可以确定任务长度和进度量,则应该更新进度条的值,将其切换回确定模式。

下面是一个创建进度条的示例,其中 task 为返回关于某个操作进度信息的对象:

progressBar = new JProgressBar(0, task.getLengthOfTask());
progressBar.setValue(0);
progressBar.setStringPainted(true);
下面是更新进度条值的示例:
progressBar.setValue(task.getCurrent());
下面的示例将进度条设置为不确定模式,然后在知道任务长度后切换回确定模式:
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);

有关进一步的文档和完整的示例,请参阅《The Java Tutorial》中的 How to Monitor Progress 一节。

警告:此类的序列化对象与以后的 Swing 版本不兼容。当前序列化支持适用于短期存储,或适用于在运行相同 Swing 版本的应用程序之间进行 RMI(Remote Method Invocation,远程方法调用)。从 1.4 版本开始,已在 java.beans 包中添加了支持所有 JavaBeansTM 长期存储的功能。请参见 XMLEncoder

另请参见:
BasicProgressBarUI

嵌套类摘要
protected  class JProgressBar.AccessibleJProgressBar
          此类实现 JProgressBar 类的可访问性支持。
 
从类 javax.swing.JComponent 继承的嵌套类/接口
JComponent.AccessibleJComponent
 
从类 java.awt.Container 继承的嵌套类/接口
Container.AccessibleAWTContainer
 
从类 java.awt.Component 继承的嵌套类/接口
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
字段摘要
protected  ChangeEvent changeEvent
          每个实例只需要一个 ChangeEvent,因为事件的惟一感兴趣属性是不可变源,即进度条。
protected  ChangeListener changeListener
          侦听由进度条的模型发送的更改事件,并将其再次指派到在此进度条上注册的更改事件侦听器。
protected  BoundedRangeModel model
          保存进度条数据的对象。
protected  int orientation
          进度条是水平的还是垂直的。
protected  boolean paintBorder
          是否显示围绕进度条的边框。
protected  boolean paintString
          是否以文本方式在进度条上显示字符串。
protected  String progressString
          可以在进度条上显示的可选字符串。
 
从类 javax.swing.JComponent 继承的字段
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
从类 java.awt.Component 继承的字段
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
从接口 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
 
从接口 java.awt.image.ImageObserver 继承的字段
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
构造方法摘要
JProgressBar()
          创建一个显示边框但不带进度字符串的水平进度条。
JProgressBar(BoundedRangeModel newModel)
          创建使用指定的保存进度条数据模型的水平进度条。
JProgressBar(int orient)
          创建具有指定方向(JProgressBar.VERTICALJProgressBar.HORIZONTAL)的进度条。
JProgressBar(int min, int max)
          创建具有指定最小值和最大值的水平进度条。
JProgressBar(int orient, int min, int max)
          创建使用指定方向、最小值和最大值的进度条。
 
方法摘要
 void addChangeListener(ChangeListener l)
          将指定的 ChangeListener 添加到进度条。
protected  ChangeListener createChangeListener()
          要以不同方式处理来自模型的更改事件的子类可以重写此方法,以返回自定义 ChangeListener 实现的实例。
protected  void fireStateChanged()
          通知对 ChangeEvent 感兴趣的所有已注册侦听器。
 AccessibleContext getAccessibleContext()
          获得与此 JProgressBar 关联的 AccessibleContext
 ChangeListener[] getChangeListeners()
          返回通过 addChangeListener 添加到此进度条的所有 ChangeListener 组成的数组。
 int getMaximum()
          返回进度条的最大值,该值存储在进度条的 BoundedRangeModel 中。
 int getMinimum()
          返回进度条的最小值,该值存储在进度条的 BoundedRangeModel 中。
 BoundedRangeModel getModel()
          返回此进度条使用的数据模型。
 int getOrientation()
          根据进度条的方向返回 JProgressBar.VERTICALJProgressBar.HORIZONTAL
 double getPercentComplete()
          返回进度条的完成百分比。
 String getString()
          返回进度字符串的当前值。
 ProgressBarUI getUI()
          返回呈现此组件的外观对象。
 String getUIClassID()
          返回呈现此组件的外观类的名称。
 int getValue()
          返回进度条的当前值,该值存储在进度条的 BoundedRangeModel 中。
 boolean isBorderPainted()
          返回 borderPainted 属性。
 boolean isIndeterminate()
          返回 indeterminate 属性的值。
 boolean isStringPainted()
          返回 stringPainted 属性的值。
protected  void paintBorder(Graphics g)
          如果 borderPainted 属性为 true,则绘制进度条的边框。
protected  String paramString()
          返回此 JProgressBar 的字符串表示形式。
 void removeChangeListener(ChangeListener l)
          从进度条移除 ChangeListener
 void setBorderPainted(boolean b)
          设置 borderPainted 属性,如果进度条应该绘制其边框,则此属性为 true
 void setIndeterminate(boolean newValue)
          设置进度条的 indeterminate 属性,该属性确定进度条处于确定模式中还是处于不确定模式中。
 void setMaximum(int n)
          将进度条的最大值(存储在进度条的数据模型中)设置为 n
 void setMinimum(int n)
          将进度条的最小值(存储在进度条的数据模型中)设置为 n
 void setModel(BoundedRangeModel newModel)
          设置 JProgressBar 使用的数据模型。
 void setOrientation(int newOrientation)
          将进度条的方向设置为 newOrientation(必须为 JProgressBar.VERTICALJProgressBar.HORIZONTAL)。
 void setString(String s)
          设置进度字符串的值。
 void setStringPainted(boolean b)
          设置 stringPainted 属性的值,该属性确定进度条是否应该呈现进度字符串。
 void setUI(ProgressBarUI ui)
          设置呈现此组件的外观对象。
 void setValue(int n)
          将进度条的当前值(存储在进度条的数据模型中)设置为 n
 void updateUI()
          将 UI 属性重置为当前外观对应的值。
 
从类 javax.swing.JComponent 继承的方法
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, 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, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, 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, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
从类 java.awt.Container 继承的方法
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, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
从类 java.awt.Component 继承的方法
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, 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, 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, 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, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

字段详细信息

orientation

protected int orientation
进度条是水平的还是垂直的。默认值为 HORIZONTAL

另请参见:
setOrientation(int)

paintBorder

protected boolean paintBorder
是否显示围绕进度条的边框。默认值为 true

另请参见:
setBorderPainted(boolean)

model

protected BoundedRangeModel model
保存进度条数据的对象。

另请参见:
setModel(javax.swing.BoundedRangeModel)

progressString

protected String progressString
可以在进度条上显示的可选字符串。默认值为 null。将此值设置为非 null 值并不表示将显示该字符串。

另请参见:
setString(java.lang.String)

paintString

protected boolean paintString
是否以文本方式在进度条上显示字符串。默认值为 false。将此值设置为 true 可在进度条上呈现进度的文本显示。如果 progressStringnull,则在进度条上显示完成的百分比。否则,在进度条上呈现 progressString

另请参见:
setStringPainted(boolean)

changeEvent

protected transient ChangeEvent changeEvent
每个实例只需要一个 ChangeEvent,因为事件的惟一感兴趣属性是不可变源,即进度条。


changeListener

protected ChangeListener changeListener
侦听由进度条的模型发送的更改事件,并将其再次指派到在此进度条上注册的更改事件侦听器。

另请参见:
createChangeListener()
构造方法详细信息

JProgressBar

public JProgressBar()
创建一个显示边框但不带进度字符串的水平进度条。初始值和最小值都为 0,最大值为 100。

另请参见:
setOrientation(int), setBorderPainted(boolean), setStringPainted(boolean), setString(java.lang.String), setIndeterminate(boolean)

微信小程序

微信扫一扫体验

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部