0

I have the following code:

public class FileLoader extends SwingWorker(Void, Void) {
    @Override
    private Void doInBackground() {
        loadFiles();
    }
}

public class LogInPage {

    private FileLoader fileLoader = new FileLoader();

    public LogInPage() {
        fileLoader.execute();
    }

    loginButtonActionPerformed(ActionEvent evt) {
        //wait for files to finish loading
        //while displaying a waiting cursor

        showMainForm();
    }
}

My question would be:

After clicking the button, I would want all the files to be loaded first (while displaying an hourglass cursor and progress bar) before showing the main form.

I have done this before with Thread's join() but was not able to do the same with SwingWorker.

I have read about overriding done() and implementing listeners but I can't apply it here.

Any help?

Thanks.

amor214
  • 201
  • 2
  • 11

1 Answers1

0

From what you're saying and contrary to what you think, I think you can actually use SwingWorker's done() method. Before execute(), disable the button, start a busy animation, whatever, then in the done() method, do whatever it is you need to do to continue the program. That's what it's for :-)

You should also look at the SwingWorker.publish() and process() to send and receive the progress bar events.

See also: How do I wait for a SwingWorker's doInBackground() method?

Community
  • 1
  • 1
Jim
  • 3,476
  • 4
  • 23
  • 33