javax.swing

Class 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

UNKNOWN: updated to 1.2

Field Summary
protected AccessibleContextaccessibleContext
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
voidclose()

Hides the dialog and stops any measurements.

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

AccessibleContextgetAccessibleContext()
Gets the accessible context.
intgetMaximum()
Return the maximum or end value of your operation.
intgetMillisToDecideToPopup()
Returns the amount of milliseconds to wait until the ProgressMonitor should decide whether a progress dialog is to be shown or not.
intgetMillisToPopup()
Returns the number of milliseconds to wait before displaying the progress dialog.
intgetMinimum()
Returns the minimum or start value of the operation.
StringgetNote()
Returns a message which is shown in the progress dialog.
booleanisCanceled()
Returns whether the user canceled the operation.
voidsetMaximum(int maximum)

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

voidsetMillisToDecideToPopup(int time)
Sets the amount of milliseconds to wait until the ProgressMonitor should decide whether a progress dialog is to be shown or not.
voidsetMillisToPopup(int time)
Sets the number of milliseconds to wait before displaying the progress dialog.
voidsetMinimum(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.

voidsetNote(String note)

Set the message shown in the progess dialog.

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

voidsetProgress(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.

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 {@link 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.

getAccessibleContext

public AccessibleContext getAccessibleContext()
Gets the accessible context.

Returns: the accessible context.

getMaximum

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

Returns: Maximum or end value.

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.

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: ProgressMonitor

getMinimum

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

Returns: Minimum or start value of the operation.

getNote

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

Returns: The changeable message visible in the progress dialog.

isCanceled

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

Returns: Whether the operation was canceled.

setMaximum

public void setMaximum(int maximum)

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

Parameters: maximum

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.

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

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.

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.

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.