How to make JTable column which contains different types of data? (some cells contain images, some cells contain text)
Like this:
I tried to make CellRenderer but it doesn't work.
col.setCellRenderer(new DefaultTableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if (value instanceof ImageIcon) {
ImageIcon img = (ImageIcon) value;
setIcon(img);
setHorizontalAlignment(JLabel.CENTER);
}
else {
setValue(value);
}
return this;
}
});
It gives me this strange output:
Without renderer it outputs text and numbers fine but doesn't display images: