Progress bar no updating resolved
I just wanted to share my solution into making my progress bar work while my program process time consuming method.
Before, my progress bar won't get updated when the for loop in my time consuming method starts working.
My solution was to put my time consuming method using SwingWorker. It allows my progress bar to get updated and I can open up another menu.
Here's my solution.
somewhere in my code. I used to just call my time consuming method by calling it such as
...
wipeSecure(file, totalNumberofPasses); // call wipeSecure method with file and number of passes as input
....
It fails to update my progress bar while that method is called. Inside my wipeSecure() method, I create the update for my progress bar as the inner loop is finished. I have to wrap the wipeSecure() method using SwingWorker and now I have replaced it with.
SwingWorker<Void, Void> loadWorker = new SwingWorker<Void, Void>()
{
protected Void doInBackground() throws Exception
{
// calling my time intensive code below.
wipeButton.setEnabled(false); // disable wipeButton
wipeSecure(file, totalNumberofPasses); // call wipeSecure method with file and number of passes as input
log.append("end of wipe()..... " + "\n");
return null;
}
// the done() method gets called when the background process above is complete.
// it's called on the EDT.
protected void done()
{
wipeButton.setEnabled(true); // enable wipeButton
aProgressBar.setValue(0); // set default progress bar
}
};
loadWorker.execute();