I can\'t update my progressbar... this is my code
Thread t=new Thread(new Runnable(){
public void run(){
int i=1;
jProgBar.setMin
Use a model instead of the JProgressBar directly:
DefaultBoundedRangeModel model = new DefaultBoundedRangeModel();
JProgressBar bar = new JProgressBar(model);
// Somewhere else, perhaps in another Thread
model.setValue(i)
The following example works fine:
public static void main(String[] args) throws InterruptedException {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200, 100);
frame.setVisible(true);
final DefaultBoundedRangeModel model = new DefaultBoundedRangeModel();
frame.add(new JProgressBar(model));
Thread t = new Thread(new Runnable() {
public void run() {
int i = 1;
model.setMinimum(0);
model.setMaximum(100);
try {
while (i <= 100 || true) {
model.setValue(i);
i++;
Thread.sleep(50);
}
} catch (InterruptedException ex) {
model.setValue(model.getMaximum());
}
}
});
t.start();
Thread.sleep(2000);
t.interrupt();
}