Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vaadin:带有IndexedContainer的网格中的图像_Vaadin_Vaadin7 - Fatal编程技术网

Vaadin:带有IndexedContainer的网格中的图像

Vaadin:带有IndexedContainer的网格中的图像,vaadin,vaadin7,Vaadin,Vaadin7,因此,我尝试使用IndexedContainer将图像添加到网格中,代码如下: //picture String imgURL = (String)ds.child(PHOTO).getValue();//gets the image URL from the DB System.out.println(imgURL); ExternalResource picture = new ExternalResource(imgURL); System.out.

因此,我尝试使用IndexedContainer将图像添加到网格中,代码如下:

    //picture
    String imgURL = (String)ds.child(PHOTO).getValue();//gets the image URL from the DB
    System.out.println(imgURL);
    ExternalResource picture = new ExternalResource(imgURL);
    System.out.println(picture.getURL());
    Image image = new Image(PICTURE, picture);
    image.setHeight("5px");
    item.getItemProperty(PICTURE).setValue(image);

我得到的不是图片,而是图像对象的
toString()
。两个
println
都打印正确的URL。还请注意,这适用于表格,但不适用于网格。知道为什么吗?

如果要在Vaadin网格列中显示图像,需要设置ImageRenderer,请参见第ImageRenderer段

示例:将列定义为

grid.addColumn("picture", Resource.class).setRenderer(new ImageRenderer());
然后添加一个资源作为列值

grid.addRow(new ThemeResource("img/copernicus-128px.jpg"), "Nicolaus Copernicus", 1543);

在您的情况下,它是
外部资源
。不需要
图像
组件。

哪个println打印了正确的URL?这幅画有什么价值?两者都有。这是网格单元格中显示的内容:com.vaadin.ui。Image@1e37c05dDid答案有帮助吗?请给出反馈。唉,我使用的是IndexedContainer,所以这并不适用。这只是一个例子。您的
IndexedContainer
需要一个列,其中的值类型为
Resource
,例如
ThemeResource
,然后设置渲染器,如
grid.getColumn(“yourColumn”).setRenderer(new ImageRenderer())
。我已经完成了所有这些。正如我所说,相同的代码适用于表。我已经离开了,决定换成餐桌。可能问题是我声明该列具有
Image
类型,而不是
Resource
。这个答案是正确的。问题是我尝试将属性(列)的类型设置为
ExternalResource
。使用
Resource.class
并将
ExternalResource
ThemeResource
的值传递给属性就可以实现这一点。谢谢。你可以把它标记为答案,然后,看。