Search code examples
comboboxvaadinreadonlyinvisible

Vaadin ComboBox invisible when readonly


Why does a Vaadin ComboBox get invisible when doing setReadOnly(true)?

Screenshots

normal normal ComboBox - visible

invisible ComboBox with setReadOnly(true) - invisible

The source code

import java.util.List;   
import com.vaadin.ui.ComboBox;

public class PropertyComboBox extends ComboBox
{
    public PropertyComboBox(List<String> properties)
    {
        super();
        for(String property: properties) {this.addItem(property);}
        this.setImmediate(true);
        this.setMultiSelect(false);

        this.setNewItemsAllowed(false);
        this.setInputPrompt("Property");
        this.setReadOnly(true);
    }
}

Solution

  • If you are trying to create a combo box in which the user can't write anything, check out the NativeSelect component.

    From the API doc:

    This is a simple drop-down select without, for instance, support for multiselect, new items, lazyloading, and other advanced features. Sometimes "native" select without all the bells-and-whistles of the ComboBox is a better choice.

    If you don't need these features, then you should definetely consider using NativeSelect.