tags:

views:

792

answers:

2

I have created a jTable and have put an ImageIcon objects in one of the columns. I would like to know how I can get it to display the image rather than the image name as a string.

Thanks

+3  A: 

You have to implement a TableCellRenderer and set it for the respective column.

A TableCellRenderer has just one method which returns a Component to display in a table cell. However, you probably need to adjust the row heights when you want to display images, since the rows won't adjust automatically to their content.

For how to use custom renderers you can refer to the Java Tutorials.

Joey
You don't *need* to implement a TableCellRenderer as overriding the Column Class to ImageIcon will display an Image for you. You're correct in stating you need to adjust row heights though
MrWiggles
Oh, and learned another thing. Though JTables are a real pain to work with when you go beyond simple tasks with them -.-
Joey
+1  A: 

You need to provide a custom table cell renderer to show the image. You will find examples if you Google jtable image renderer. See here for one.

Mark