• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Lazy loading of image in table cell with custom renderer

 
Matthew Fleming
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JTable#setValueAt(...) should cause the particular cell to be repainted.
 
Matthew Fleming
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic