javax.swing
Class ProgressMonitor

java.lang.Object
  extended by javax.swing.ProgressMonitor

public class ProgressMonitor
extends Object

Using this class you can easily monitor tasks where you cannot estimate the duration exactly.

A ProgressMonitor instance waits until the first time setProgress is called. When millisToDecideToPopup time elapsed the instance estimates the duration until the whole operation is completed. If this duration exceeds millisToPopup a non-modal dialog with a message and a progress bar is shown.

The value of millisToDecideToPopup defaults to 500 and millisToPopup to 2000.

Since:
1.2

Field Summary
protected  AccessibleContext accessibleContext
          The accessible content for this component
 
Constructor Summary
ProgressMonitor(Component component, Object message, String note, int minimum, int maximum)
          Creates a new ProgressMonitor instance.
 
Method Summary
 void close()
          Hides the dialog and stops any measurements.
 AccessibleContext getAccessibleContext()
          Gets the accessible context.
 int getMaximum()
          Return the maximum or end value of your operation.
 int getMillisToDecideToPopup()
          Returns the amount of milliseconds to wait until the ProgressMonitor should decide whether a progress dialog is to be shown or not.
 int getMillisToPopup()
          Returns the number of milliseconds to wait before displaying the progress dialog.
 int getMinimum()
          Returns the minimum or start value of the operation.
 String getNote()
          Returns a message which is shown in the progress dialog.
 boolean isCanceled()
          Returns whether the user canceled the operation.
 void setMaximum(int maximum)
          Sets the maximum or end value of the operation to the given integer.
 void setMillisToDecideToPopup(int time)
          Sets the amount of milliseconds to wait until the ProgressMonitor should decide whether a progress dialog is to be shown or not.
 void setMillisToPopup(int time)
          Sets the number of milliseconds to wait before displaying the progress dialog.
 void setMinimum(int minimum)
          Use this method to set the minimum or start value of your operation.
 void setNote(String note)
          Set the message shown in the progess dialog.
 void setProgress(int progress)
          Updates the progress value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

accessibleContext

protected AccessibleContext accessibleContext
The accessible content for this component

Constructor Detail

ProgressMonitor

public ProgressMonitor(Component component,
                       Object message,
                       String note,
                       int minimum,
                       int maximum)
Creates a new ProgressMonitor instance. This is used to monitor a task and pops up a dialog if the task is taking a long time to run.

Parameters:
component - The parent component of the progress dialog or null.
message - A constant message object which works in the way it does in JOptionPane.
note - A string message which can be changed while the operation goes on.
minimum - The minimum value for the operation (start value).
maximum - The maximum value for the operation (end value).
Method Detail

close

public void close()

Hides the dialog and stops any measurements.

Has no effect when setProgress is not at least called once.


setProgress

public void setProgress(int progress)

Updates the progress value.

When called for the first time this initializes a timer which decides after millisToDecideToPopup time whether to show a progress dialog or not.

If the progress value equals or exceeds the maximum value the progress dialog is closed automatically.

Parameters:
progress - New progress value.

getMinimum

public int getMinimum()
Returns the minimum or start value of the operation.

Returns:
Minimum or start value of the operation.

setMinimum

public void setMinimum(int minimum)

Use this method to set the minimum or start value of your operation.

For typical application like copy operation this will be zero.

Keep in mind that changing this value after the progress dialog is made visible has no effect upon the progress bar.

Parameters:
minimum - The new minimum value.

getMaximum

public int getMaximum()
Return the maximum or end value of your operation.

Returns:
Maximum or end value.

setMaximum

public void setMaximum(int maximum)

Sets the maximum or end value of the operation to the given integer.

Parameters:
maximum -

isCanceled

public boolean isCanceled()
Returns whether the user canceled the operation.

Returns:
Whether the operation was canceled.

getMillisToDecideToPopup

public int getMillisToDecideToPopup()
Returns the amount of milliseconds to wait until the ProgressMonitor should decide whether a progress dialog is to be shown or not.

Returns:
The duration in milliseconds.

setMillisToDecideToPopup

public void setMillisToDecideToPopup(int time)
Sets the amount of milliseconds to wait until the ProgressMonitor should decide whether a progress dialog is to be shown or not.

This method has no effect when the progress dialog is already visible.

Parameters:
time - The duration in milliseconds.

getMillisToPopup

public int getMillisToPopup()
Returns the number of milliseconds to wait before displaying the progress dialog. The default value is 2000.

Returns:
The number of milliseconds.
See Also:
setMillisToPopup(int)

setMillisToPopup

public void setMillisToPopup(int time)
Sets the number of milliseconds to wait before displaying the progress dialog.

Parameters:
time - the number of milliseconds.
See Also:
getMillisToPopup()

getNote

public String getNote()
Returns a message which is shown in the progress dialog.

Returns:
The changeable message visible in the progress dialog.

setNote

public void setNote(String note)

Set the message shown in the progess dialog.

Changing the note while the progress dialog is visible is possible.

Parameters:
note - A message shown in the progress dialog.

getAccessibleContext

public AccessibleContext getAccessibleContext()
Gets the accessible context.

Returns:
the accessible context.