-
Bug
-
Resolution: Fixed
-
P5
-
1.3.1, 6
-
b74
-
generic
-
generic
Name: bsC130419 Date: 07/25/2001
java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)
To reproduce this problem, use a ProgressMonitor. Give it a long task so that
the progress bar pops up. If at some point you call setProgress() with a value
that is smaller than the largest value that has been set so far, the progress
bar does not back up to reflect this.
To demonstrate the problem, run the ProgressMonitorDemo with this code:
http://java.sun.com/docs/books/tutorial/uiswing/components/example-swing/Progres
sMonitorDemo.java
http://java.sun.com/docs/books/tutorial/uiswing/components/example-swing/SwingWo
rker.java
but in place of the LongTask code provided in the tutorial example:
http://java.sun.com/docs/books/tutorial/uiswing/components/example-swing/LongTas
k.java
Use this code for LongTask:
/** Uses a SwingWorker to perform a time-consuming (and utterly fake) task. */
public class LongTask {
private int lengthOfTask;
private int current = 500;
private String statMessage;
LongTask() {
//Compute length of task...
//In a real program, this would figure out
//the number of bytes to read or whatever.
lengthOfTask = 1000;
}
/**
* Called from ProgressBarDemo to start the task.
*/
void go() {
current = 0;
final SwingWorker worker = new SwingWorker() {
public Object construct() {
return new ActualTask();
}
};
worker.start();
}
/**
* Called from ProgressBarDemo to find out how much work needs
* to be done.
*/
int getLengthOfTask() {
return lengthOfTask;
}
/**
* Called from ProgressBarDemo to find out how much has been done.
*/
int getCurrent() {
return current;
}
void stop() {
current = lengthOfTask;
}
/**
* Called from ProgressBarDemo to find out if the task has completed.
*/
boolean done() {
if (current >= lengthOfTask)
return true;
else
return false;
}
String getMessage() {
return statMessage;
}
/**
* The actual long running task. This runs in a SwingWorker thread.
*/
class ActualTask {
ActualTask () {
//Fake a long task,
//making a random amount of progress every second.
while (current < lengthOfTask) {
try {
Thread.sleep(1000); //sleep for a second
current += Math.random() * 100 - Math.random() * 100; //make
some progress
if (current > lengthOfTask) {
current = lengthOfTask;
}
statMessage = "Completed " + current +
" out of " + lengthOfTask + ".";
} catch (InterruptedException e) {}
}
}
}
}
(Review ID: 128800)
======================================================================
java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)
To reproduce this problem, use a ProgressMonitor. Give it a long task so that
the progress bar pops up. If at some point you call setProgress() with a value
that is smaller than the largest value that has been set so far, the progress
bar does not back up to reflect this.
To demonstrate the problem, run the ProgressMonitorDemo with this code:
http://java.sun.com/docs/books/tutorial/uiswing/components/example-swing/Progres
sMonitorDemo.java
http://java.sun.com/docs/books/tutorial/uiswing/components/example-swing/SwingWo
rker.java
but in place of the LongTask code provided in the tutorial example:
http://java.sun.com/docs/books/tutorial/uiswing/components/example-swing/LongTas
k.java
Use this code for LongTask:
/** Uses a SwingWorker to perform a time-consuming (and utterly fake) task. */
public class LongTask {
private int lengthOfTask;
private int current = 500;
private String statMessage;
LongTask() {
//Compute length of task...
//In a real program, this would figure out
//the number of bytes to read or whatever.
lengthOfTask = 1000;
}
/**
* Called from ProgressBarDemo to start the task.
*/
void go() {
current = 0;
final SwingWorker worker = new SwingWorker() {
public Object construct() {
return new ActualTask();
}
};
worker.start();
}
/**
* Called from ProgressBarDemo to find out how much work needs
* to be done.
*/
int getLengthOfTask() {
return lengthOfTask;
}
/**
* Called from ProgressBarDemo to find out how much has been done.
*/
int getCurrent() {
return current;
}
void stop() {
current = lengthOfTask;
}
/**
* Called from ProgressBarDemo to find out if the task has completed.
*/
boolean done() {
if (current >= lengthOfTask)
return true;
else
return false;
}
String getMessage() {
return statMessage;
}
/**
* The actual long running task. This runs in a SwingWorker thread.
*/
class ActualTask {
ActualTask () {
//Fake a long task,
//making a random amount of progress every second.
while (current < lengthOfTask) {
try {
Thread.sleep(1000); //sleep for a second
current += Math.random() * 100 - Math.random() * 100; //make
some progress
if (current > lengthOfTask) {
current = lengthOfTask;
}
statMessage = "Completed " + current +
" out of " + lengthOfTask + ".";
} catch (InterruptedException e) {}
}
}
}
}
(Review ID: 128800)
======================================================================
- relates to
-
JDK-6533883 ProgressMonitor's popup starts to behave differently in 1.6
- Closed