hoger qassim hoger qassim - 1 year ago 82
Java Question

Java using jProgressBar within loop

i build an Application and i have a button do a lot of things when i press it the application is freeze it for some second. So i just want put a jProgressBar here is my code :

String s="";
long l=System.currentTimeMillis();

for(int k=0;k<jTable3.getRowCount();k++){
s=jTable3.getValueAt(k, 0).toString();
long l2=System.currentTimeMillis();
JOptionPane.showMessageDialog(rootPane, "We are done in just "+(l2-l)+" MS");

Any help or suggest ?

Answer Source

What you need to do is perform your lengthy/taxing operations on another thread, and then, from that thread, adjust the value of your JProgressBar. The progress will then be visible.

Some information on concurrency and threads.