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.
Asked
Active
Viewed 476 times
0
-
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 Answers
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
.

Raj
- 942
- 1
- 7
- 12
-
i read about multithreading and came across java SwingWorker.. that worked thanks !! – user3682478 Jun 07 '14 at 17:56
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