p p
p p

Reputation:

How do I get a an image to display in JTable in java swing

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

Upvotes: 2

Views: 4315

Answers (2)

Joey
Joey

Reputation: 354516

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.

Upvotes: 3

Mark
Mark

Reputation: 29119

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.

Upvotes: 1

Related Questions