Click here to Skip to main content
15,889,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,

how to insert image or imageIcon in to table's cell in java???

i have tried to insert it as object of imageIcon like this
<br />
<br />
table.setValueAt(new ImageIcon("image.gif"), row, column);<br />
<br />


but it displays the name of the image only in the table cell???

can anyone help me in this problem or if there is another solution?? :)

Thanks in advance

Basem,
Posted
Updated 30-Dec-09 21:22pm
v2

1 solution

Look here[^] for details on the table.

[disclaimer]
I don't have java at work so can't check this
[/disclaimer]

Either create the imageicon up front:
ImageIcon icon = new ImageIcon("image.gif");
table.setValueAt(icon, row, column);


Or you can try overriding the renderer for your icon field:

static class IconRenderer extends DefaultTableCellRenderer {
  public IconRenderer() { super(); }

  public void setValue(Object value) {
    if (value == null) {
      setText("");
    }
    else
    {
      setIcon(value);
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900