Class ListBox<T>

  • Type Parameters:
    T - the type of the items contained by this component
    All Implemented Interfaces:
    com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.HasComponents, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ListBox<T>,​T>,​T>, com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ListBox<T>,​T>,​T>, HasTooltip, com.vaadin.flow.data.binder.HasItemComponents<T>, com.vaadin.flow.data.provider.HasDataView<T,​Void,​ListBoxDataView<T>>, com.vaadin.flow.data.provider.HasListDataView<T,​ListBoxListDataView<T>>, com.vaadin.flow.data.selection.SingleSelect<ListBox<T>,​T>, Serializable

    public class ListBox<T>
    extends ListBoxBase<ListBox<T>,​T,​T>
    implements com.vaadin.flow.data.selection.SingleSelect<ListBox<T>,​T>
    List Box allows the user to select one or more values from a scrollable list of items. Although its functionally similar to Checkbox Group and Radio Button Group, List Box is designed to be used as a lightweight scrollable selection list rather than a form input field.

    List Box also supports using dividers to group related items. Use them sparingly to avoid creating unnecessary visual clutter. List Box supports both single and multiple selection. The former allows the user to select only one item while the latter enables multiple items to be selected.

    Items can be rendered with rich content instead of plain text. This can be useful to provide additional information in a more legible fashion than appending it to the item text.

    Best Practices:
    List Box is not designed to be used as an input field in forms, and lacks features like label, helper, and validation errors. List Box is best suited to be used as a lightweight, scrollable, single-column list for single or multi-selection of items.

    Author:
    Vaadin Ltd
    See Also:
    MultiSelectListBox, Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class com.vaadin.flow.component.AbstractField

        com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<C extends com.vaadin.flow.component.Component,​V extends Object>
      • Nested classes/interfaces inherited from interface com.vaadin.flow.data.binder.HasItemComponents

        com.vaadin.flow.data.binder.HasItemComponents.ItemComponent<T extends Object>
      • Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasValue

        com.vaadin.flow.component.HasValue.ValueChangeEvent<V extends Object>, com.vaadin.flow.component.HasValue.ValueChangeListener<E extends com.vaadin.flow.component.HasValue.ValueChangeEvent<?>>
    • Constructor Summary

      Constructors 
      Constructor Description
      ListBox()
      Creates a new list box component.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected boolean valueEquals​(T value1, T value2)
      Compares two value instances to each other to determine whether they are equal.
      • Methods inherited from class com.vaadin.flow.component.AbstractSinglePropertyField

        getSynchronizationRegistration, hasValidValue, setPresentationValue, setSynchronizedEvent
      • Methods inherited from class com.vaadin.flow.component.AbstractField

        addValueChangeListener, getEmptyValue, getValue, isEmpty, setModelValue, setValue
      • Methods inherited from class com.vaadin.flow.component.Component

        addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, scrollIntoView, set, setElement, setId, setVisible
      • Methods inherited from interface com.vaadin.flow.component.AttachNotifier

        addAttachListener
      • Methods inherited from interface com.vaadin.flow.component.DetachNotifier

        addDetachListener
      • Methods inherited from interface com.vaadin.flow.component.HasComponents

        add, add, add, addComponentAsFirst, addComponentAtIndex, remove, remove, removeAll
      • Methods inherited from interface com.vaadin.flow.component.HasElement

        getElement
      • Methods inherited from interface com.vaadin.flow.component.HasEnabled

        isEnabled, setEnabled
      • Methods inherited from interface com.vaadin.flow.data.binder.HasItemComponents

        addComponents, getItemPosition, prependComponents
      • Methods inherited from interface com.vaadin.flow.data.provider.HasListDataView

        setItems, setItems
      • Methods inherited from interface com.vaadin.flow.component.HasSize

        getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull
      • Methods inherited from interface com.vaadin.flow.component.HasStyle

        addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
      • Methods inherited from interface com.vaadin.flow.component.HasValue

        addValueChangeListener, clear, getEmptyValue, getOptionalValue, getValue, isEmpty, setValue
      • Methods inherited from interface com.vaadin.flow.component.HasValueAndElement

        isReadOnly, isRequiredIndicatorVisible, setReadOnly, setRequiredIndicatorVisible
    • Constructor Detail

      • ListBox

        public ListBox()
        Creates a new list box component.
    • Method Detail

      • valueEquals

        protected boolean valueEquals​(T value1,
                                      T value2)
        Compares two value instances to each other to determine whether they are equal. Equality is used to determine whether to update internal state and fire an event when AbstractField.setValue(Object) or AbstractField.setModelValue(Object, boolean) is called. Subclasses can override this method to define an alternative comparison method instead of Object.equals(Object).
        Overrides:
        valueEquals in class com.vaadin.flow.component.AbstractField<ListBox<T>,​T>
        Parameters:
        value1 - the first instance
        value2 - the second instance
        Returns:
        true if the instances are equal; otherwise false