Class SCheckbox

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.AbstractField<com.vaadin.flow.component.checkbox.Checkbox, Boolean>
com.vaadin.flow.component.AbstractSinglePropertyField<com.vaadin.flow.component.checkbox.Checkbox, Boolean>
com.vaadin.flow.component.checkbox.Checkbox
com.vaadin.swingbridge.surrogates.SCheckbox
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<com.vaadin.flow.component.checkbox.Checkbox>, com.vaadin.flow.component.ClickNotifier<com.vaadin.flow.component.checkbox.Checkbox>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<com.vaadin.flow.component.checkbox.Checkbox>, com.vaadin.flow.component.FocusNotifier<com.vaadin.flow.component.checkbox.Checkbox>, com.vaadin.flow.component.HasAriaDescription, com.vaadin.flow.component.HasAriaLabel, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasHelper, com.vaadin.flow.component.HasLabel, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasTheme, com.vaadin.flow.component.HasValidation, com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.checkbox.Checkbox, Boolean>, Boolean>, com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.checkbox.Checkbox, Boolean>, Boolean>, com.vaadin.flow.component.shared.HasThemeVariant<com.vaadin.flow.component.checkbox.CheckboxVariant>, com.vaadin.flow.component.shared.HasTooltip, com.vaadin.flow.component.shared.HasValidationProperties, com.vaadin.flow.component.shared.InputField<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.checkbox.Checkbox, Boolean>, Boolean>, com.vaadin.flow.data.binder.HasValidator<Boolean>, ComponentMixin, ItemSelectable, Serializable

@StyleSheet("emul/scheckbox.css") public class SCheckbox extends com.vaadin.flow.component.checkbox.Checkbox implements ComponentMixin, ItemSelectable
Surrogate for Checkbox — the AWT 1.0 checkbox, not JCheckBox. Extends Vaadin Checkbox directly (is-a) and picks up the AWT Component API from ComponentMixin.
SCheckbox c = new SCheckbox("Enable sync", false);
c.addItemListener(e -> log(e.getStateChange() == ItemEvent.SELECTED));
c.setState(true);       // silent: no ItemEvent, exactly as in AWT
c.setRadioLook(true);   // renders as a radio glyph; behaviour unchanged

Only the browser posts events

AWT's setState fires nothing — only the toolkit peer posts an ItemEvent. That inverts Swing, where setSelected drives a ButtonModel fan-out, and it is why the value listener below gates on isFromClient() instead of carrying a preventPeerEvents flag: a server-side push is precisely the case AWT stays silent for, so there is no echo to suppress.

Why not AbstractButtonMixin

The mixin already owns addItemListener / fireItemStateChanged / getSelectedObjects, so the overlap is larger than it was for SButton — but the mixin's ItemEvent fan-out is driven off the ButtonModel, so a programmatic setSelected delivers an event. That is exactly the behaviour AWT does not have, on the most-used method of the class. The rest of the mixin (getModel, setAction, the icon family, mnemonic, doClick, ActionListener, ChangeListener) has no java.awt.Checkbox counterpart at all, and it sits on JComponentMixin, which would bring borders and client properties to a java.awt.Component. Duplicating the ~30-line fan-out is the cheaper mistake (SD_scheckbox).

The radio glyph

A grouped java.awt.Checkbox paints as a radio button — in the JDK a live peer property read off group != null, not a construction-time type choice. setRadioLook(boolean) reproduces that as the emul-radio theme name, which emul/scheckbox.css turns into a round box with a dot — via a documented style property for the shape and a ::part override for the glyph, for the reason that file records. Appearance only: mutual exclusion lives on the emulator vaadinx.awt.Checkbox, which owns the CheckboxGroup (D_buttongroup_browser_click), and this class un-checks on a second click like any checkbox.
See Also:
  • Constructor Details

    • SCheckbox

      public SCheckbox()
    • SCheckbox

      public SCheckbox(String label)
    • SCheckbox

      public SCheckbox(String label, boolean state)
      Parameters:
      label - null renders a captionless box and reads back as "" (accepted R_vaadin_first loss; the emulator keeps the JDK's null)
  • Method Details

    • getState

      public boolean getState()
    • setState

      public void setState(boolean state)
      Fires no ItemEvent — AWT's programmatic setter is silent.
    • getSelectedObjects

      public Object[] getSelectedObjects()
      Specified by:
      getSelectedObjects in interface ItemSelectable
      Returns:
      a one-element array holding the label when checked, else null — AWT's convention here, which java.awt.List does not share (it answers an empty array)
    • setLabel

      public void setLabel(String label)
      Never mix with setLabelComponent — Vaadin's setLabel evicts a label component child.
      Specified by:
      setLabel in interface com.vaadin.flow.component.HasLabel
      Overrides:
      setLabel in class com.vaadin.flow.component.checkbox.Checkbox
      Parameters:
      label - null clears the caption and reads back as ""; the changed-only guard is AWT's
    • isRadioLook

      public boolean isRadioLook()
    • setRadioLook

      public void setRadioLook(boolean radioLook)
      Switches between the checkbox and radio glyphs. Appearance only — the mutual exclusion an AWT CheckboxGroup implies is the emulator's job.
      Parameters:
      radioLook - DOM-backed via the emul-radio theme name, so the round-trip is lossless and no field shadow is needed
    • addItemListener

      public void addItemListener(ItemListener l)
      Specified by:
      addItemListener in interface ItemSelectable
    • removeItemListener

      public void removeItemListener(ItemListener l)
      Specified by:
      removeItemListener in interface ItemSelectable
    • getItemListeners

      public ItemListener[] getItemListeners()
    • processItemEvent

      protected void processItemEvent(ItemEvent e)
      AWT's dispatch hook. Overriding it (and calling super) is the documented way for java.awt.Checkbox subclasses to intercept every toggle before its listeners see it, so it stays the single funnel the peer's value change routes through.
    • setEnabled

      public void setEnabled(boolean enabled)
      Routes into the mixin chain so SD_auto_pce's auto-PCE fires.

      Not forced by a shadow — Vaadin Checkbox declares no setEnabled, so ComponentMixin's default wins on specificity anyway. Kept to pin the choice in source, as SJCheckBox does.

      Specified by:
      setEnabled in interface ComponentMixin
      Specified by:
      setEnabled in interface com.vaadin.flow.component.HasEnabled
    • validate

      public void validate()
      Widens Checkbox.validate() to public so the mixin's validate() contract is satisfied — a class member beats an interface default, and narrowing the visibility would not compile.
      Specified by:
      validate in interface ComponentMixin
      Overrides:
      validate in class com.vaadin.flow.component.checkbox.Checkbox
    • paramString

      protected String paramString()
      AWT's Checkbox.paramString omits the label clause when null.
    • getAccessibleContext

      public AccessibleContext getAccessibleContext()