Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to show an image (jpg or gif) in a JTable cell ?

 
Edisandro Bessa
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I have a database table called "product" with various fields where one of these fields contains a small picture representing the product.

How can I show this picture in my JTable product list screen ?

BTW, looking at J2SE API I could not find a way to use .ico images in my Java apps. I only found how to use .jpg, .gif and .png files. Is there some way to use .ico images in my java programs ?

Your comments are really really appreciated.

Thanks a lot,
Edisandro Bessa.
[ September 27, 2006: Message edited by: Edisandro Bessa ]
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
e.g. the third column (#2)

TableColumn tc = table.getColumnModel().getColumn(2);
tc.setCellRenderer(new ImageRenderer());

and the renderer, where 'value' is the path to the image file e.g. "test.gif"


[EDIT]
that's what you get when you copy/paste/modify/post and don't read
lbl = new JLabel(new ImageIcon((String)value));
should be just
lbl.setIcon(...)
[ September 27, 2006: Message edited by: Michael Dunn ]
 
Edisandro Bessa
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Michael,

Very simple right ?

Thanks a lot for your prompt reply.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic