Search code examples
vaadin8vaadin-grid

Vaadin 8 grid: Size image in grid cell?


I try to render an image in a grid cell as follows:

grid.addColumn(probe ->
    new ThemeResource("img/" + probe.getStructureData().getImageFileName()),
    new ImageRenderer()
).setCaption("Structure");

I want to set the size of the image in pixel. How can I do this? It seems the ImageRenderer has no method for this. Of cause I could size my images before. But I would like to add a big image that should be shown as tooltip and a small version of the same image should be shown in the grid cell. I would like to avoid adding the same image in 2 sizes.

Thank you!


Solution

  • Try doing it this way.

    grid.addComponentColumn(probe -> {
        Image image = new Image("", new ThemeResource("img/" + probe.getStructureData().getImageFileName()));
        image.setWidth(100, Sizeable.Unit.PIXELS);
        image.setHeight(100, Sizeable.Unit.PIXELS);
    
        return image;
    }).setCaption("Structure");