Java Backgroundworker: Scope of Widget to be updated unclear

Posted by erlord on Stack Overflow See other posts from Stack Overflow or by erlord
Published on 2010-03-21T22:54:53Z Indexed on 2010/03/21 23:01 UTC
Read the original article Hit count: 338

Hi all,

I am trying to understand the mechanism of org.jdesktop.swingx.BackgroundWorker. Their javadoc presents following example:

   final JLabel label;
   class MeaningOfLifeFinder implements BackgroundListener {
       public void doInBackground(BackgroundEvent evt) {
           String meaningOfLife = findTheMeaningOfLife();
           evt.getWorker().publish(meaningOfLife);
       }

       public void process(BackgroundEvent evt) {
           label.setText("" + evt.getData());
       }

       public void done(BackgroundEvent evt) {}
       public void started(BackgroundEvent evt) {}
   }

   (new MeaningOfLifeFinder()).execute();

Apart from the fact that I doubt the result will ever get published, I wonder how label is passed to the process method, where it is being updated. I thought it's scope is limited to the outside of the BackgroudListener implementation. Quite confused I am ... any answers for me?

Thanks in advance

© Stack Overflow or respective owner

Related posts about java

Related posts about backgroundworker