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.
ComboBox<Boolean> with caption
Hello,
I am trying to add custom captions to a Boolean-ComboBox. Instead of true, false I want to display domain-specific terms, like "is active", "not active" etc.
The only solution I found would be to implement a wrapper for Boolean which contains the caption text, then use an ItemCaptionGenerator. This I would have to do for each Boolean-Type field in my database.
This seems like mighty overkill for my intended purpose. Is there a simpler way, maybe similar to the old setCaption(Item, String)?
Thanks
Stefan
Hello,
Something like that ?
ComboBox<Boolean> c = new ComboBox<Boolean>();
c.setItems(true, false);
c.setItemCaptionGenerator(bool -> {return bool?"Active":"Inactive";});
Hello Jean-Christophe,
exactly like that. I really have to read up on those lambda expressions I guess.
Thank you very much!
It can be shortened even more:
ComboBox<Boolean> c = new ComboBox<>();
c.setItems(true, false);
c.setItemCaptionGenerator(bool -> bool?"Active":"Inactive");