I am trying to get an image to be displayed on Vaadin Flow Grid but without success. Below is my code:
private Grid<Integer> grid = new Grid<>();
grid.addColumn(i -> i).setHeader("Number");
grid.addColumn(i -> new ThemeResource("../theme/ajax-loader.gif")).setHeader("Preview");
grid.setItems(IntStream.range(1,21).boxed());
What I get is a Number column and a Preview column showing the text “…/theme/ajax-loader.gif”.
I am new to Vaadin and hope to get some guidance on the above.
Thanks Kaspar for the suggestion.
I am getting the “com.vaadin.flow.component.html.Image@29d00c” displayed at the Preview column as shown in my attachment.
How do I set the grid to display them as image instead of text?
private Grid<Integer> grid = new Grid<>();
grid.addColumn(i -> i).setHeader("Number");
grid.addColumn(i -> new Image("theme/ajax-loader.gif", "alt text")).setHeader("Preview");
grid.setItems(IntStream.range(1,10).boxed());
oops my mistake, you should use a ComponentRenderer grid.addColumn(new ComponentRenderer<>(i -> {})); or the short form of that: grid.addComponentColumn(i -> {})
grid.addComponentColumn(i -> new Image("theme/ajax-loader.gif", "alt text")).setHeader("Preview");