aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to show an image (jpg or gif) in a JTable cell ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to show an image (jpg or gif) in a JTable cell ?" Watch "How to show an image (jpg or gif) in a JTable cell ?" New topic
Author

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

Edisandro Bessa
Ranch Hand

Joined: Jan 19, 2006
Posts: 584
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 ]

"If someone asks you to do something you don't know how to, don't tell I don't know, tell I can learn instead." - Myself
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
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

Joined: Jan 19, 2006
Posts: 584
Hi Michael,

Very simple right ?

Thanks a lot for your prompt reply.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to show an image (jpg or gif) in a JTable cell ?