Class Checkbox

  • All Implemented Interfaces:
    com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<Checkbox>, com.vaadin.flow.component.ClickNotifier<Checkbox>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<Checkbox>, com.vaadin.flow.component.FocusNotifier<Checkbox>, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasLabel, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Checkbox,​Boolean>,​Boolean>, com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Checkbox,​Boolean>,​Boolean>, HasTooltip, Serializable

    public class Checkbox
    extends GeneratedVaadinCheckbox<Checkbox,​Boolean>
    implements com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasLabel, HasTooltip
    Checkbox is an input field representing a binary choice.

    Checkbox also has an indeterminate mode, see isIndeterminate() for more info.

    Use CheckboxGroup to group related items. Individual checkboxes should be used for options that are not related to each other in any way.

    Author:
    Vaadin Ltd
    See Also:
    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.component.BlurNotifier

        com.vaadin.flow.component.BlurNotifier.BlurEvent<C extends com.vaadin.flow.component.Component>
      • Nested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifier

        com.vaadin.flow.component.FocusNotifier.FocusEvent<C extends com.vaadin.flow.component.Component>
      • 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
      Checkbox()
      Default constructor.
      Checkbox​(boolean initialValue)
      Constructs a checkbox with the initial value.
      Checkbox​(boolean initialValue, com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Checkbox,​Boolean>> listener)
      Constructs a checkbox with the initial value and value change listener.
      Checkbox​(String labelText)
      Constructs a checkbox with the initial label text.
      Checkbox​(String labelText, boolean initialValue)
      Constructs a checkbox with the initial value.
      Checkbox​(String labelText, boolean initialValue, com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Checkbox,​Boolean>> listener)
      Constructs a checkbox with the initial value, label text and value change listener.
      Checkbox​(String label, com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Checkbox,​Boolean>> listener)
      Constructs a checkbox with the initial label text and value change listener.
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      String getLabel()
      Get the current label text.
      boolean isAutofocus()
      Get the state for the auto-focus property of the checkbox.
      boolean isIndeterminate()
      Get the indeterminate state of the checkbox.
      void setAriaLabel​(String ariaLabel)
      Set the accessibility label of this checkbox.
      void setAutofocus​(boolean autofocus)
      Set the checkbox to be input focused when the page loads.
      void setIndeterminate​(boolean indeterminate)
      Set the indeterminate state of the checkbox.
      void setLabel​(String label)
      Set the current label text of this checkbox.
      void setLabelAsHtml​(String htmlContent)
      Deprecated.
      Since 23.2, this API is deprecated in favor of setLabelComponent(Component)
      void setLabelComponent​(com.vaadin.flow.component.Component component)
      Replaces the label content with the given label component.
      • 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, valueEquals
      • 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, onAttach, onDetach, onEnabledStateChanged, scrollIntoView, set, setElement, setId, setVisible
      • Methods inherited from interface com.vaadin.flow.component.AttachNotifier

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

        addBlurListener
      • Methods inherited from interface com.vaadin.flow.component.ClickNotifier

        addClickListener, addClickShortcut
      • Methods inherited from interface com.vaadin.flow.component.DetachNotifier

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

        addFocusShortcut, blur, focus, getTabIndex, setTabIndex
      • Methods inherited from interface com.vaadin.flow.component.FocusNotifier

        addFocusListener
      • 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.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

        clear, getOptionalValue
      • Methods inherited from interface com.vaadin.flow.component.HasValueAndElement

        isReadOnly, isRequiredIndicatorVisible, setReadOnly, setRequiredIndicatorVisible
    • Constructor Detail

      • Checkbox

        public Checkbox()
        Default constructor.
      • Checkbox

        public Checkbox​(String labelText)
        Constructs a checkbox with the initial label text.
        Parameters:
        labelText - the label text to set
        See Also:
        setLabel(String)
      • Checkbox

        public Checkbox​(boolean initialValue)
        Constructs a checkbox with the initial value.
        Parameters:
        initialValue - the initial value
        See Also:
        AbstractField.setValue(Object)
      • Checkbox

        public Checkbox​(String labelText,
                        boolean initialValue)
        Constructs a checkbox with the initial value.
        Parameters:
        labelText - the label text to set
        initialValue - the initial value
        See Also:
        setLabel(String), AbstractField.setValue(Object)
      • Checkbox

        public Checkbox​(String label,
                        com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Checkbox,​Boolean>> listener)
        Constructs a checkbox with the initial label text and value change listener.
        Parameters:
        label - the label text to set
        listener - the value change listener to add
        See Also:
        setLabel(String), AbstractField.addValueChangeListener(ValueChangeListener)
      • Checkbox

        public Checkbox​(boolean initialValue,
                        com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Checkbox,​Boolean>> listener)
        Constructs a checkbox with the initial value and value change listener.
        Parameters:
        initialValue - the initial value
        listener - the value change listener to add
        See Also:
        AbstractField.setValue(Object), AbstractField.addValueChangeListener(ValueChangeListener)
      • Checkbox

        public Checkbox​(String labelText,
                        boolean initialValue,
                        com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Checkbox,​Boolean>> listener)
        Constructs a checkbox with the initial value, label text and value change listener.
        Parameters:
        labelText - the label text to set
        initialValue - the initial value
        listener - the value change listener to add
        See Also:
        setLabel(String), AbstractField.setValue(Object), AbstractField.addValueChangeListener(ValueChangeListener)
    • Method Detail

      • getLabel

        public String getLabel()
        Get the current label text.
        Specified by:
        getLabel in interface com.vaadin.flow.component.HasLabel
        Returns:
        the current label text
      • setLabel

        public void setLabel​(String label)
        Set the current label text of this checkbox.
        Specified by:
        setLabel in interface com.vaadin.flow.component.HasLabel
        Parameters:
        label - the label text to set
      • setLabelAsHtml

        @Deprecated
        public void setLabelAsHtml​(String htmlContent)
        Deprecated.
        Since 23.2, this API is deprecated in favor of setLabelComponent(Component)
        Set the current label text of this checkbox with HTML formatting.

        XSS vulnerability warning: the given HTML is rendered in the browser as is and the developer is responsible for ensuring no harmful HTML is used.

        Parameters:
        htmlContent - the label html to set
      • setLabelComponent

        public void setLabelComponent​(com.vaadin.flow.component.Component component)
        Replaces the label content with the given label component.
        Parameters:
        component - the component to be added to the label.
        Since:
        23.1
      • setAriaLabel

        public void setAriaLabel​(String ariaLabel)
        Set the accessibility label of this checkbox.
        Parameters:
        ariaLabel - the accessibility label to set
        See Also:
        aria-label at MDN
      • setAutofocus

        public void setAutofocus​(boolean autofocus)
        Set the checkbox to be input focused when the page loads.
        Overrides:
        setAutofocus in class GeneratedVaadinCheckbox<Checkbox,​Boolean>
        Parameters:
        autofocus - the boolean value to set
      • isAutofocus

        public boolean isAutofocus()
        Get the state for the auto-focus property of the checkbox.

        This property is not synchronized automatically from the client side, so the returned value may not be the same as in client side.

        Returns:
        the autofocus property from the checkbox
      • setIndeterminate

        public void setIndeterminate​(boolean indeterminate)
        Set the indeterminate state of the checkbox.

        NOTE: As according to the HTML5 standard, this has only effect on the visual appearance, not on the checked value!

        Overrides:
        setIndeterminate in class GeneratedVaadinCheckbox<Checkbox,​Boolean>
        Parameters:
        indeterminate - the boolean value to set
        See Also:
        isIndeterminate()
      • isIndeterminate

        public boolean isIndeterminate()
        Get the indeterminate state of the checkbox. The default value is false.

        An indeterminate checkbox is neither checked nor unchecked. A typical use case is a “Select All” checkbox indicating that some, but not all, items are selected. When the user clicks an indeterminate checkbox, it is no longer indeterminate, and the checked value also changes.

        NOTE: As according to the HTML5 standard, this has only effect on the visual appearance, not on the checked value!

        Returns:
        the indeterminate property from the checkbox