I am working on a Java program, which reads text files does some probability calculations. Reading files and all related calculations are done in a while loop.
I had created a GUI using JFrame, where i had added a Progress bar (using JProgressBar) to show the progress since the program takes a while to process the files.
The code looks like -
while( there are more files to read )
{
Read this file ;
Do calculations ;
Update progress bar ;
}
Now, the problem is once the while loop starts and the first file is processed, the JFrame simply freezes. The progress bar does not get updated and i cannot press any button in the JFrame. Once the while loop ends the frame is updated and the progress bar is updated to its final value (hence, the progress bar starts from 0 then pauses then finally goes to 100).
Could some one explain why is the JFrame freezing ? Is it possible to update it (progress bar in the JFrame) in the while loop iterations ?
Thanks !
You're doing your time intense task in the event dispatch thread (EDT). This is a bad idea as the EDT also updates the UI. Therefore if this thread is blocked no update to the UI is done.