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.

Product icon

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

ComboBox<Boolean> with caption

Stefan Quosbarth
5 years ago Apr 21, 2017 10:46am
Jean-Christophe Gueriaud
5 years ago Apr 21, 2017 11:56am

Something like that ?

ComboBox<Boolean> c = new ComboBox<Boolean>();
       c.setItems(true, false);
       c.setItemCaptionGenerator(bool -> {return bool?"Active":"Inactive";});
Stefan Quosbarth
5 years ago Apr 21, 2017 12:18pm
Johannes Dahlström
5 years ago Apr 21, 2017 7:02pm

It can be shortened even more:

ComboBox<Boolean> c = new ComboBox<>();
c.setItems(true, false);
c.setItemCaptionGenerator(bool -> bool?"Active":"Inactive");