Reputation: 163
I want to display multiple images in a single cell of a jtable.I know how to display a single image in a cell but how to do the same in case of multiple images?
Upvotes: 1
Views: 636
Reputation: 347234
There are at least two ways I can think of doing this...
You could merge all the images into a single image and allow the default TableCellRenderer
to render the result as normal
Or...
You need to supply your own TableCellRenderer
capable of taking the multiple images and displaying them.
Probably the simplest would be to use a JPanel
as a base and add a JLabel
per image. This would be a rather expensive process (assuming your have a dynamic number of images per cell), as you would need to remove all the labels from the panel and add the new ones for EACH cell.
See Using Custom Renderers for more details.
Upvotes: 2
Reputation: 109813
I want to display multiple images in a single cell of a jtable.I know how to display a single image in a cell but how to do the same in case of multiple images?
I'm wouldn't going this way, because XxxRanderer is called from every mouse and Key events over visible JTables Rectangle in the JViewport,
prepare this image before, put together all images to one and put only one Icon/ImageIcon to XxxTableModel
DefaultCellRenderer returns JLabel by default, add proper LayoutManager to JLabel and laid there images, save images to local variable to avoiding any FileIO on runtime
Upvotes: 2