Combobox dropmenu items - change color for some items

Hello,

I am thinking is there a way to change color of some of the items in dropmenu items. I got workers in this combobox…

I wanna make item with color red when not employeed and normal color when he is employeed.

Someone maybe know how to resolve this problem ?

Hi, one option involves using ComponentRenderer. Something like:

ComboBox<String> comboBox = new ComboBox<>();
comboBox.setItems("Option one", "Option two", "Option three");
comboBox.setRenderer(new ComponentRenderer<>(str -> {
    Span text = new Span(str);
    if (str.equals("Option one")) {
        text.getStyle().set("color", "red");
    } else {
        text.getStyle().set("color", "navy");
    }
    return text;
}));