如何在Java中将图像或imageIcon插入表的单元格中 [英] how to insert image or imageIcon in to table's cell in java

查看:90
本文介绍了如何在Java中将图像或imageIcon插入表的单元格中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

如何将图像或imageIcon插入到Java中表的单元格中?

我试图像这样
将其插入为imageIcon的对象

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 />



但是它仅在表格单元格中显示图像的名称??

谁能帮助我解决这个问题,或者还有其他解决方案? :)

在此先感谢

Basem,



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,

推荐答案

查找此处 [^ ],以获取表格上的详细信息.

[免责声明]
我没有上班的Java,所以无法检查此
[/免责声明]

要么先创建imageicon,要么:
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);
    }
}


这篇关于如何在Java中将图像或imageIcon插入表的单元格中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆