2
votes

I have the following code...

runNow.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent arg0) {

    final Search s = (Search) node.getUserObject();

    // Swing worker
    SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
        @Override
        public Void doInBackground() {
            s.run();
            return null;
        }

        @Override
        public void done() {
            window.updateResultsPanel(s.getResults(), s.getName());
         }
    };

    worker.run();

    }
});

This is a popup menu action which should create a new SwingWorker, free up the GUI, do some work, then update the results of the window. However, right now when I click the menu item the GUI becomes locked up until the work completes which is baffling, the whole point of using a SwingWorker is so that won't happen.

Any ideas as to what I'm doing wrong would be greatly appreciated.

-Cody

2

2 Answers

4
votes

You should be calling SwingWorker#execute to start the worker, not run

Run is exposed by the Runnable interface, but execute actually schedules the worker to run at some time in the future.

1
votes

Have to change method SwingWorker.run() to SwingWorker.execute() and it worked like a charm.