📄 progress.html
字号:
</ul>If you decide to use a progress monitor <em>and</em>the task you are monitoring is reading from an input stream,use the<a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/ProgressMonitorInputStream.html"><strong><code>ProgressMonitorInputStream</code></strong></a> class.</blockquote><h3><a name="api">The Progress Monitoring API</a></h3><blockquote>The following tables list the commonly usedAPI for using progress bars and progress monitors.Because <code>JProgressBar</code> is a subclass of<code>JComponent</code>,other methods you are likely to call on a<code>JProgressBar</code> are listed in <a href="jcomponent.html">The JComponent Class</a>.Note that<code>ProgressMonitor</code> is a subclass of <code>Object</code>and is not a visual component.<p>The API for monitoring progressfalls into these categories:<ul><li><a href="#progressbarapi">Creating the Progress Bar</a><li><a href="#contentsapi">Setting or Getting the Progress Bar's Constraints/Values</a><li><a href="#looksapi">Controlling the Progress Bar's Appearance</a><li><a href="#progressmonapi">Creating the Progress Monitor</a><li><a href="#monitorapi">Configuring the Progress Monitor</a><li><a href="#terminateapi">Terminating the Progress Monitor</a></ul><p><table border=1><caption><a name="progressbarapi">Creating the Progress Bar</a></caption><tr><th>Constructor</th><th>Purpose</th></tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JProgressBar.html#JProgressBar()">JProgressBar()</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JProgressBar.html#JProgressBar(int, int)">JProgressBar(int, int)</a> </td> <td>Create a horizontal progress bar. The no-argument constructor initializes the progress bar with a minimum and initial value of 0 and a maximum of 100. The constructor with two integer arguments specifies the minimum and maximum values. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JProgressBar.html#JProgressBar(int)">JProgressBar(int)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JProgressBar.html#JProgressBar(int, int, int)">JProgressBar(int, int, int)</a> </td> <td>Create a progress bar with the specified orientation, which can be either <code>JProgressBar.HORIZONTAL</code> or <code>JProgressBar.VERTICAL</code>. The optional second and third arguments specify minimum and maximum values. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JProgressBar.html#JProgressBar(javax.swing.BoundedRangeModel)">JProgressBar(BoundedRangeModel)</a> </td> <td>Create a horizontal progress bar with the specified range model. </td> </tr></table><p><table border=1><caption><a name="contentsapi">Setting or Getting the Progress Bar's Constraints/Values</a></caption><tr><th>Method</th><th>Purpose</th></tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JProgressBar.html#setValue(int)">void setValue(int)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JProgressBar.html#getValue()">int getValue()</a> </td> <td>Set or get the current value of the progress bar. The value is constrained by the minimum and maximum values. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JProgressBar.html#getPercentComplete()">double getPercentComplete()</a> </td> <td>Get the percent complete for the progress bar. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JProgressBar.html#setMinimum(int)">void setMinimum(int)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JProgressBar.html#getMinimum()">int getMinimum()</a> </td> <td>Set or get the minimum value of the progress bar. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JProgressBar.html#setMaximum(int)">void setMaximum(int)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JProgressBar.html#getMaximum()">int getMaximum()</a> </td> <td>Set or get the maximum value of the progress bar. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JProgressBar.html#setModel(javax.swing.BoundedRangeModel)">void setModel(BoundedRangeModel)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JProgressBar.html#getModel()">BoundedRangeModel getModel()</a> </td> <td>Set or get the model used by the progress bar. The model establishes the progress bar's constraints and values, so you can use it directly as an alternative to using the individual set/get methods listed above. </td> </tr></table><p><table border=1><caption><a name="looksapi">Controlling the Progress Bar's Appearance</a></caption><tr><th>Method</th><th>Purpose</th></tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JProgressBar.html#setIndeterminate(boolean)">void setIndeterminate(boolean)</a> </td> <td>By specifying <code>true</code>, put the progress bar into indeterminate mode. Specifying <code>false</code> puts the progress bar back into its default, determinate mode. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JProgressBar.html#setOrientation(int)">void setOrientation(int)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JProgressBar.html#getOrientation()">int getOrientation()</a> </td> <td>Set or get whether the progress bar is vertical or horizontal. Acceptable values are <code>JProgressBar.VERTICAL</code> or <code>JProgressBar.HORIZONTAL</code>. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JProgressBar.html#setBorderPainted(boolean)">void setBorderPainted(boolean)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JProgressBar.html#isBorderPainted()">boolean isBorderPainted()</a> </td> <td>Set or get whether the progress bar has a border. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JProgressBar.html#setStringPainted(boolean)">void setStringPainted(boolean)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JProgressBar.html#isStringPainted()">boolean isStringPainted()</a> </td> <td>Set or get whether the progress bar displays a percent string. By default, the value of the percent string is the value returned by <code>getPercentComplete</code> formatted as a percent. You can set the string to be displayed with <code>setString</code>. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JProgressBar.html#setString(java.lang.String)">void setString(String)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JProgressBar.html#getString()">String getString()</a> </td> <td>Set or get the percent string. </td> </tr></table><p><table border=1><caption><a name="progressmonapi">Creating the Progress Monitor</a></caption><tr><th>Method or Constructor</th><th>Purpose</th></tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/ProgressMonitor.html#ProgressMonitor(java.awt.Component, java.lang.Object, java.lang.String, int, int)">ProgressMonitor(Component, Object, String, int, int)</a> </td> <td>Create a progress monitor. The <code>Component</code> argument is the parent for the monitor's dialog. The <code>Object</code> argument is a message to put on the <a href="dialog.html">option pane</a> within the dialog. The value of this object is typically a <code>String</code>. The <code>String</code> argument is a changeable status note. The final two <code>int</code> arguments set the minimum and maximum values, respectively, for the progress bar used in the dialog. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/ProgressMonitorInputStream.html#getProgressMonitor()">ProgressMonitor getProgressMonitor()</a> <br><em>(in <code>ProgressMonitorInputStream</code>)</em> </td> <td>Gets a progress monitor that monitors reading from an input stream. </td> </tr></table><p> <table border=1><caption><a name="monitorapi">Configuring the Progress Monitor</a></caption><tr><th>Method</th><th>Purpose</th></tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JProgressBar.html#setMinimum(int)">void setMinimum(int)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JProgressBar.html#getMinimum()">int getMinimum()</a> </td> <td>Set or get the minimum value of the progress monitor. This value is used by the monitor to set up the progress bar in the dialog. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JProgressBar.html#setMaximum(int)">void setMaximum(int)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JProgressBar.html#getMaximum()">int getMaximum()</a> </td> <td>Set or get the maximum value of the progress monitor. This value is used by the monitor to set up the progress bar in the dialog. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/ProgressMonitor.html#setProgress(int)">void setProgress(int)</a> </td> <td>Update the monitor's progress. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/ProgressMonitor.html#setNote(java.lang.String)"><code>void setNote(String)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/ProgressMonitor.html#getNote()">String getNote()</a> </td> <td>Set or get the status note. This note is displayed on the dialog. To omit the status note from the dialog, provide <code>null</code> as the third argument to the monitor's constructor. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/ProgressMonitor.html#setMillisToDecideToPopup(int)">void setMillisToDecideToPopup(int)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/ProgressMonitor.html#getMillisToDecideToPopup()">int getMillisToDecideToPopup()</a> </td> <td>Set or get the time after which the monitor should decide whether to popup a dialog. </td> </tr></table><p><table border=1><caption><a name="terminateapi">Terminating the Progress Monitor</a></caption><tr><th>Method</th><th>Purpose</th></tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/ProgressMonitor.html#close()">void close()</a> </td> <td>Close the progress monitor. This disposes of the dialog. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/ProgressMonitor.html#isCanceled()">boolean isCanceled()</a> </td> <td>Determine whether the user pressed the <strong>Cancel</strong> button. </td> </tr></table></blockquote><h3><a name="eg">Examples that Monitor Progress</a></h3><blockquote>This following examples use <code>JProgressBar</code> or<code>ProgressMonitor</code>.<p><table><tr><th align=left> Example</th><th align=left> Where Described</th><th align=left> Notes</th></tr><tr><td> <a href="examples/index.html#ProgressBarDemo"><code>ProgressBarDemo</code></a></td><td> This section</td><td> Uses a basic progress bar to show progress on a task running in a separate thread.</td></tr><tr><td> <a href="examples/index.html#ProgressBarDemo2"><code>ProgressBarDemo2</code></a></td><td> This section</td><td> Uses a basic progress bar to show progress on a task running in a separate thread.</td></tr><tr><td> <a href="examples/index.html#ProgressMonitorDemo"><code>ProgressMonitorDemo</code></a></td><td> This section</td><td> Modification of the previous example that uses a progress monitor instead of a progress bar.</td></tr></table></blockquote> </blockquote> <div class=NavBit> <a target=_top href=passwordfield.html>« Previous</a> • <a target=_top href=../TOC.html>Trail</a> • <a target=_top href=rootpane.html>Next »</a> </div> </div> <div id=Footer><div id=TagNotes> Problems with the examples? Try <a target="_blank" href=../../information/run-examples.html>Compiling and Running the Examples: FAQs</a>. <br> Complaints? Compliments? Suggestions? <a target="_blank" href="http://developer.sun.com/contact/tutorial_feedback.jsp">Give us your feedback</a>.<br><br> <a target="_blank" href="../../information/copyright.html">Copyright</a> 1995-2006 Sun Microsystems, Inc. All rights reserved. <span id=Download></span></div> </div> <div class=PrintHeaders> <b>Previous page:</b> How to Use Password Fields <br><b>Next page:</b> How to Use Root Panes </div> </body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -