Java - SwingWorker - problem in done() method

Posted by Yatendra Goel on Stack Overflow See other posts from Stack Overflow or by Yatendra Goel
Published on 2010-04-28T19:04:19Z Indexed on 2010/04/28 19:07 UTC
Read the original article Hit count: 303

Filed under:
|
|
|

I am using javax.swing.SwingWorker for the first time.

I want to update a JLabel from the interim result published by the swing worker as follows:

publish("Published String");

Now to update the JLabel, I have coded the following:

process(List<String> chunks) {
    if (chunks.size() > 0) {
        String text = chunks.get(chunks.size() - 1);
        label.setText(text);
    }
}

The above code works but my problem(or to be more specific, my doubt) is as follows:

The above swing worker task is an annonymous inner class so it can access label field.

But what if I want to make the swing worker class a non-inner class. Should I need to pass label as an argument to the constructor of swing worker class so that the process() method can access.

Or Is there any other way?

What approach does other developer follow to update UI components from the swing worker class' result when the swing worker class is not an inner class?

© Stack Overflow or respective owner

Related posts about java

Related posts about swing