Hi
I need to show an image thumbnail in one of jTable cells
But I don't know how to do it!
I'm using netbeans to design GUI .
How can I do that?

Thanks

Hi
I did it as this:

class mcr extends DefaultTableCellRenderer{
        public Class getColumnClass(int c) {
            return ImageIcon.class;
        }
    }

and used like this:

jTable1.getColumn("image").setCellRenderer(new mcr());
        DefaultTableModel Tmodel=(DefaultTableModel) jTable1.getModel();
        jTable1.setRowHeight(80);
        ImageIcon icon = new ImageIcon("/home/ariyan/Desktop/71290452.jpg");
        Tmodel.setValueAt(icon, 0, 3);

But it just shows toString of ImageIcon and not the image!

getColumnClass is part of TableModel not TableCellRenderer. If you mean to override methods then use the @Override annotation that things like that don't happen. See the examples/tutorials that that Google search throws up.

Hi
I did as this:

class ImageRenderer extends DefaultTableCellRenderer {
      JLabel lbl = new JLabel();
      public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        lbl.setIcon((ImageIcon)value);
        return lbl;
      }
    }

and used like this:

ImageIcon icon = new ImageIcon("/home/ariyan/Desktop/pic/4vn2hdi.jpg");
        jTable1.getColumnModel().getColumn(3).setCellRenderer(new ImageRenderer());
        DefaultTableModel Tmodel=(DefaultTableModel) jTable1.getModel();
        jTable1.setRowHeight(150);
        Tmodel.setValueAt(icon, 0, 3);

Is this correct?
Or needs change?

This article has been dead for over six months. Start a new discussion instead.