File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Lazy loading of image in table cell with custom renderer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Lazy loading of image in table cell with custom renderer" Watch "Lazy loading of image in table cell with custom renderer" New topic
Author

Lazy loading of image in table cell with custom renderer

Matthew Fleming
Greenhorn

Joined: Oct 29, 2009
Posts: 8
Hi,

I have a table with a custom cell renderer made from a custom component that includes a JLabel with an ImageIcon. The images for the ImageIcons have to be downloaded from Amazon Web Services, and this takes awhile. I'd like the textual parts of the custom component to display right away, and the images to be added as they become available. But the obvious way of handling this (start a background thread to download the image; update the JLabel when it completes) doesn't work, presumably because of the peculiar way custom renderers are handled (same renderer used for multiple cells, so that renderer.repaint() does nothing).

Currently I am just getting the image and updating the JLabel with it in the custom component's getTableCellRendererComponent() method. This means that all the images are downloaded before any of the table's cells are painted.

I've spent a fair while struggling with this; I'd be very interested to learn what the solution might be, if there is one. Thanks!

Matthew Fleming
DermVision
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4638
    
    5

JTable#setValueAt(...) should cause the particular cell to be repainted.


luck, db
There are no new questions, but there may be new answers.
Matthew Fleming
Greenhorn

Joined: Oct 29, 2009
Posts: 8
Darryl Burke wrote:JTable#setValueAt(...) should cause the particular cell to be repainted.


Maybe it should, but it doesn't. However, AbstractTableModel.fireTableCellUpdated(row, col) does.

So the solution looks like this:



Where I have this in my custom renderer:



I'm a bit rusty with java; have been doing mostly iOS programming lately. I must say this sort of thing is a lot easier in Obj C/iOS ...

Anyway, thanks for the suggestion, which got me going in the right direction.

Matthew Fleming
DermVision
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Lazy loading of image in table cell with custom renderer