|
-
July 22nd, 1999, 04:42 PM
#1
How to show ImageIcon inside cell of JTable
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 [email protected]
-
July 23rd, 1999, 12:24 AM
#2
Re: How to show ImageIcon inside cell of JTable
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...
-
July 23rd, 1999, 01:15 PM
#3
Re: How to show ImageIcon inside cell of JTable
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(" ");
}
}
}
-
July 23rd, 1999, 04:16 PM
#4
Re: How to show ImageIcon inside cell of JTable
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|