0

I am executing several SQL queries in the function evoked by a button in java. I wish to show the status of the same, and I am using a jProgressBar for the same. But the problem is it will only update after the button has finished executing itself, making it pointless to show the progress. How can I display the actual progress of the executing button.

  • check into threadworkers, it sounds like your program only has one thread running right now. Also, some code would be great! – Kyte Jun 04 '14 at 16:40
  • yes.. i realized i had been missing n threads on which i had no idea.. read about them and successfully implemented the same through SwingWorker.. – user3682478 Jun 07 '14 at 17:57
  • excellent! glad to hear it! – Kyte Jun 08 '14 at 23:38

2 Answers2

0

Make a thread dispatcher like this

public class ThreadDispatcher implements Runnable { 

public ThreadDispatcher() {

}

public void run() {

        //call the method related to query here        

    }           


}  

When button pressed call this class and let this class evoke your query related function.

It may be like this when you press the button.

 Thread thread = new Thread(new ThreadDispatcher());
 thread.start();
 sleep(100);

catch the InterruptedException ex.

Link for Thread example

Raj
  • 942
  • 1
  • 7
  • 12
0

You need to do the computation on a background thread, not the main thread.

Take a look at the Java SwingWorker Tutorial.

Daniel
  • 855
  • 10
  • 21