代码之家  ›  专栏  ›  技术社区  ›  jonesjames

Vaadin:带索引容器的网格中的图像

  •  1
  • jonesjames  · 技术社区  · 10 年前

    因此,我尝试使用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。还要注意,这适用于表格,但不适用于网格。知道为什么吗?

    1 回复  |  直到 10 年前
        1
  •  1
  •   Steffen Harbich    10 年前

    如果要在“瓦丁栅格”列中显示图像,则需要设置ImageRenderer,请参见 here 段落ImageRenderer。

    示例:将列定义为

    grid.addColumn("picture", Resource.class).setRenderer(new ImageRenderer());
    

    然后添加一个资源作为列值

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

    在您的情况下,它是 ExternalResource .无需 Image 组成部分