Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thumbnail inside JTable

 
Emili Calonge
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I put a thumbnail inside a JTable?

I create my table from a defaultmodel, then I try this:

And I get inside the cell the memory reference:
javax.swing.JLabel[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=8388608,maximumSize=,minimumSize=,preferredSize=,defaultIcon=javax.swing.ImageIcon@59a34,disabledIcon=,horizontalAlignment=CENTER,horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,text=,verticalAlignment=CENTER,verticalTextPosition=CENTER]

Does anybody know how to put an image inside a JTable??
 
Brian Cole
Author
Ranch Hand
Posts: 906
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try getTabla().getModel().setValueAt(icono, i, 4)
 
Emili Calonge
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I forgot to say that I had already done that, but thanks anyway, that doesn't works either, the same thing happens. I think I have to implement a ColumnRenderer, I'll search the forums for some advice. Anyone can tell me where to find it?
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll have to roll your own renderer, or find a third party renderer that does this. I believe this specific implementation is actually covered in the tutorial at the Sun website.

http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
 
Brian Cole
Author
Ranch Hand
Posts: 906
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, JTable does have default renderers
for Icons, but it won't use them unless you
return Icon.class or ImageIcon.class in your
table model's getColumnClass() method.

I should have mentioned that in my previous
posting, sorry. It's the same deal with other
column types such as Boolean, Date, and the
Number classes.

Since you say you're using DefaultTableModel,
you'll have to do something like create an
anonymous inner class to override that method.
 
Emili Calonge
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've decided not to add thumbnails on my JTable, because creating saceld images requires so much time, and as I don't really need thumbnails I prefer keeping the system fast. Thanks anyway if I have some free time I'll try to add thumbnails to the tables, but first I've got other things to do. Thanks anyway.
 
Craig Wood
Ranch Hand
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BufferedImage offers software acceleration.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic