SwingWorker doesn't work

From: Abs (abs_at_terra.com)
Date: 03/28/04


Date: Sun, 28 Mar 2004 20:16:02 +0200

Hi!

  I'm trying to use the SwingWorker class in a ListCellRenderer
with no luck. My ListCellRenderer loads a scaled down JPEG file,
this means my application locks while loading a JList of
many items. So, I thought on using that SwingWorker class
to open a separate thread for this I/O intensive task. My problem
is that I don't know how to make it work in my ListCellRenderer.
The compiler always complains with either one of the following
messages:

"Cannot refer to a non-final variable 'x' inside a inner class
defined in a different method"

"The final local variable 'x' cannot be assigned, since it is defined
in an enclosing type"

I've read all the docs about the SwingWorker class in the Sun site
but I cannot get it to work.

Here is the code:

...
public Component getListCellRendererComponent(
JList list,
Object value, // value to display
int index, // cell index
boolean isSelected, // is the cell selected
boolean cellHasFocus) // the list and the cell have the focus
{

final File file = (File)value;
setText(file.getName());
if (file.isDirectory()) {
setImage(iconToBufferedImage(fileSystemView.getSystemIcon(file)));
} else {
     BufferedImage thumbnail = (BufferedImage)thumbnails.get(value);
     if (thumbnail == null) {
         final SwingWorker worker = new SwingWorker() {
             public Object construct() {
                    thumbnail=createImage(file);
                    return thumbnail;
             }
             public void finished() {
             }
         };
         worker.start();
     }
     thumbnails.put(value,thumbnail);
     setImage(thumbnail);
}

}
...

Can someone help me, please?

Thanks in advance

-- 
Abs


Relevant Pages

  • SwingWorker doesnt work
    ... I'm trying to use the SwingWorker class in a ListCellRenderer ... My ListCellRenderer loads a scaled down JPEG file, ... this means my application locks while loading a JList of ...
    (comp.lang.java.programmer)
  • Re: SwingWorker doesnt work
    ... > I'm trying to use the SwingWorker class in a ListCellRenderer ... > with no luck. ... Please don't multipost. ...
    (comp.lang.java.programmer)