Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Add an icon in Vaadin Grid
How to dynamically add an icon to a Grid Cell. For example, i have a column that will display either True or False. I want to display some icon if the value is True/False.
Can someone please help me on this?
What you're looking for is the method grid.addComponentColumn(). Inside that component renderer you can check whatever value and return a different component depending on that value.
Grid<Person> grid = new Grid<>();
grid.addComponentColumn(item -> {
Icon icon;
if(item.isAdult()){
icon = VaadinIcon.CHECK_CIRCLE.create();
icon.setColor("green");
} else {
icon = VaadinIcon.CLOSE_CIRCLE.create();
icon.setColor("red");
}
return icon;
})
.setKey("adult")
.setHeader("Adult")
.setComparator(Comparator.comparing(Person::isAdult));
I have exactly this setup for a boolean column (except that I don't use Person class), so I left some minor improvements like icon-color and comparator here ;)