-
Bug
-
Resolution: Fixed
-
P4
-
1.4.2
-
b80
-
generic
-
generic
Once ProgressMonitor has shown its progress dialog, the dialog's progress bar no longer responds to calls to ProgressMonitor.setMaximum(), and the visual representation of the progress bar can become out of sync with the actual current/maximum values.
For instance, consider a ProgressMonitor which is measuring a task w/ minimum=0, progress=50 and maximum=100 - it's halfway complete, and the progress bar in the dialog is halfway "full". The maximum is increased to 200. The task is now 25% complete, but the progress bar is still drawn as halfway complete, and becomes "full" once progress reaches 100.
FWIW, JProgressBar performs correctly in this case, as the included test case demonstrates.
Come to think of it, this bug could also occur with setMinimum(), though I didn't test that.
This bug occurs with 1.6 (current build is b45), 1.5, 1.4.2, and probably farther back than that.
--- ProgressBarTest.java ---
// Test of ProgressBar.setMaximum() once progress has started
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ProgressBarTest extends JFrame implements ActionListener {
JProgressBar progBar;
JButton startProgBtn;
JButton addMaxBtn;
ProgressMonitor progMon;
Timer progTimer;
int current = 0;
int max = 100;
static final int incr = 10;
static final int maxIncr = 100;
public ProgressBarTest () {
super("ProgressBar Test");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().setLayout(new BorderLayout());
progMon = new ProgressMonitor(this, "Message", "Note", 0, max);
progMon.setMillisToDecideToPopup(0);
progBar = new JProgressBar();
progBar.setIndeterminate(true);
progBar.setMinimum(0);
progBar.setStringPainted(true);
getContentPane().add(progBar, BorderLayout.NORTH);
JPanel btnPnl = new JPanel();
btnPnl.setLayout(new GridLayout(1,0));
startProgBtn = new JButton("Start Progress");
startProgBtn.addActionListener(this);
btnPnl.add(startProgBtn);
addMaxBtn = new JButton("Add to Max");
addMaxBtn.addActionListener(this);
btnPnl.add(addMaxBtn);
getContentPane().add(btnPnl, BorderLayout.SOUTH);
}
public void actionPerformed(ActionEvent event) {
Object source = event.getSource();
if (source == startProgBtn) {
progTimer = new Timer(1000, this);
progBar.setIndeterminate(false);
progBar.setMaximum(max);
progBar.setValue(current);
progBar.setString(progBar.getValue() + "/" + progBar.getMaximum());
progMon.setMaximum(max);
progMon.setProgress(current);
progMon.setNote(current + "/" + progMon.getMaximum());
startProgBtn.setEnabled(false);
progTimer.start();
}
else if (source == addMaxBtn) {
max += maxIncr;
progBar.setMaximum(max);
progBar.setString(progBar.getValue() + "/" + progBar.getMaximum());
progMon.setMaximum(max);
progMon.setNote(current + "/" + progMon.getMaximum());
}
else if (source == progTimer) {
current += incr;
progBar.setValue(current);
progBar.setMaximum(max);
progBar.setString(progBar.getValue() + "/" + progBar.getMaximum());
progMon.setProgress(current);
progMon.setMaximum(max);
progMon.setNote(current + "/" + progMon.getMaximum());
}
}
public static void main(String[] args) {
ProgressBarTest test = new ProgressBarTest();
test.pack();
test.setVisible(true);
}
}
For instance, consider a ProgressMonitor which is measuring a task w/ minimum=0, progress=50 and maximum=100 - it's halfway complete, and the progress bar in the dialog is halfway "full". The maximum is increased to 200. The task is now 25% complete, but the progress bar is still drawn as halfway complete, and becomes "full" once progress reaches 100.
FWIW, JProgressBar performs correctly in this case, as the included test case demonstrates.
Come to think of it, this bug could also occur with setMinimum(), though I didn't test that.
This bug occurs with 1.6 (current build is b45), 1.5, 1.4.2, and probably farther back than that.
--- ProgressBarTest.java ---
// Test of ProgressBar.setMaximum() once progress has started
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ProgressBarTest extends JFrame implements ActionListener {
JProgressBar progBar;
JButton startProgBtn;
JButton addMaxBtn;
ProgressMonitor progMon;
Timer progTimer;
int current = 0;
int max = 100;
static final int incr = 10;
static final int maxIncr = 100;
public ProgressBarTest () {
super("ProgressBar Test");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().setLayout(new BorderLayout());
progMon = new ProgressMonitor(this, "Message", "Note", 0, max);
progMon.setMillisToDecideToPopup(0);
progBar = new JProgressBar();
progBar.setIndeterminate(true);
progBar.setMinimum(0);
progBar.setStringPainted(true);
getContentPane().add(progBar, BorderLayout.NORTH);
JPanel btnPnl = new JPanel();
btnPnl.setLayout(new GridLayout(1,0));
startProgBtn = new JButton("Start Progress");
startProgBtn.addActionListener(this);
btnPnl.add(startProgBtn);
addMaxBtn = new JButton("Add to Max");
addMaxBtn.addActionListener(this);
btnPnl.add(addMaxBtn);
getContentPane().add(btnPnl, BorderLayout.SOUTH);
}
public void actionPerformed(ActionEvent event) {
Object source = event.getSource();
if (source == startProgBtn) {
progTimer = new Timer(1000, this);
progBar.setIndeterminate(false);
progBar.setMaximum(max);
progBar.setValue(current);
progBar.setString(progBar.getValue() + "/" + progBar.getMaximum());
progMon.setMaximum(max);
progMon.setProgress(current);
progMon.setNote(current + "/" + progMon.getMaximum());
startProgBtn.setEnabled(false);
progTimer.start();
}
else if (source == addMaxBtn) {
max += maxIncr;
progBar.setMaximum(max);
progBar.setString(progBar.getValue() + "/" + progBar.getMaximum());
progMon.setMaximum(max);
progMon.setNote(current + "/" + progMon.getMaximum());
}
else if (source == progTimer) {
current += incr;
progBar.setValue(current);
progBar.setMaximum(max);
progBar.setString(progBar.getValue() + "/" + progBar.getMaximum());
progMon.setProgress(current);
progMon.setMaximum(max);
progMon.setNote(current + "/" + progMon.getMaximum());
}
}
public static void main(String[] args) {
ProgressBarTest test = new ProgressBarTest();
test.pack();
test.setVisible(true);
}
}