Click to See Complete Forum and Search --> : How to show ImageIcon inside cell of JTable
honghsu
July 22nd, 1999, 04:42 PM
I'am trying to display an ImageIcon in a JTable column. The only problem
is that I'am not seeing the ImageIcon but a String value "com.sun.java.swing.ImageIcon@266b10".
I think this is the memory address of the Icon. I thought Boolean, Number, ImageIcon and Object
are four types of data supported by JTable. Isn't it?
Does anyone has same experience and can share solution with me?
Thanks,
Hong Hsu honghsu@lucent.com
varbsjava
July 23rd, 1999, 12:24 AM
It might be a problem with your CellRenderer. Because this value is nothing but the ImageIcon.toString() value. That means the CellRenderer has converted your ImageIcon object to a string and displaying it rather than displaying as a component. So check your CellRenderer.
regards,
arun...
bgentile
July 23rd, 1999, 01:15 PM
Just set the icon of your cell renderer (if you are using or extending from DefaultTableCellRenderer, then it is just a JLabel and you can set an icon in JLabel:
class ErrorMessageCellRenderer extends DefaultTableCellRenderer
{
public void setValue(Object value)
{
if (value != null)
{
if (value instanceof ErrorMessage)
{
ErrorMessage em = (ErrorMessage)value;
setText(em.message);
setIcon(em.icon);
}
else
{
setText(value.toString());
}
}
else
{
setText(" ");
}
}
}
honghsu
July 23rd, 1999, 04:16 PM
Just modifying three line code of getColumnClass() method solves the problem. Following code say all:
public Class getColumnClass(int c) {
if(c == 0)
return ImageIcon.class;
return Object.class;
}
Thanks for your response.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.