-
Bug
-
Resolution: Fixed
-
P4
-
1.4.1
-
beta
-
x86
-
windows_nt
Name: jk109818 Date: 08/12/2002
FULL PRODUCT VERSION :
java version "1.4.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03)
Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode)
FULL OPERATING SYSTEM VERSION :
Windows NT Version 4.0
EXTRA RELEVANT SYSTEM CONFIGURATION :
Service Pack 6 installed
A DESCRIPTION OF THE PROBLEM :
When a ProgressMonitor uses a negative minimum, i.e.
ProgressMonitor monitor = new ProgressMonitor(null,
"Progress Monitor", " ", -100, +100);
the monitor dialog is displayed when the progress reaches +1
(assuming an operation that would take more than 2 seconds)
even though it should be displayed much earlier.
The documentation of ProgressMonitor does not limit the
values of 'minimum' so it should also work with negative
values.
It looks like the cause for this problem are the following
two lines in class javax.swing.JProgressMonitor, method
setProgress(int nv):
...
else if (nv >= lastDisp + reportDelta) {
lastDisp = nv;
... (maybe display progress dialog)
Since lastDisp is never initialized explicitly and
reportDelta is always positive, the 'else' expression
becomes true only for positive values of nv.
So, the real cause for the described problem is IMHO a
missing initialization of lastDisp (e.g. lastDisp = min in
the constructor).
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. create a ProgressMonitor that uses minimum = -20 and
maximum = +100
2. create a java.util.Timer that fires each second and a
corresponding TimerTask that increments the progress of the
monitor (-20, -19, -18, ..., +99, +100)
3. the ProgressMonitor will be displayed when the progress
reaches 1 (after 21 seconds)
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED: The ProgressMonitor dialog should be displayed
after one second.
ACTUAL: The ProgressMonitor dialog is displayed after 21
seconds
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.ProgressMonitor;
public class Test8 {
/**
* Tests a ProgressMonitor with the provided minimum and a maximum of
* 100. A timer is incrementing the progress each second.
*/
private static void testWithMinimum(final int min) {
final int max = 100;
final ProgressMonitor monitor = new ProgressMonitor(null,
"Testing with minimum = " + min, " ", min, max);
TimerTask task = new TimerTask() {
private int progress = min;
public void run() {
monitor.setProgress(progress++);
monitor.setNote(Integer.toString(progress));
if (progress > max || monitor.isCanceled()) {
this.cancel();
}
System.out.println(progress);
}
};
Timer timer = new Timer();
timer.schedule(task, 1000, 1000);
}
public static void main(String[] args) {
/*
* The following statement will cause the ProgressMonitor to be shown
* after 21 seconds --> should pop up after 1 second since the progress
* is incremented after 1 second the first time and the progress monitor
* should decide that the whole operation takes more than 2 seconds
* (millisToPopup)
*/
testWithMinimum(-20); // runs 120 seconds, progress incremented each
second
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
Map the actual progress range from e.g. (-100, 100) to (0,
200).
(Review ID: 160522)
======================================================================