Class SJCheckBox

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.SJCheckBox
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, ContainerMixin, AbstractButtonMixin, JComponentMixin, ItemSelectable, Serializable

public class SJCheckBox extends com.vaadin.flow.component.checkbox.Checkbox implements AbstractButtonMixin
Surrogate for JCheckBox (SD_toggle_checkbox_first_cut, restructured SD_sjtogglebutton_button_peer). Extends Vaadin Checkbox directly (is-a), rendering a checkbox glyph — JCheckBox's actual Swing look. Reaches the migrator either through :emulators.JCheckBox as peer, or as a richer-than-stock Vaadin checkbox in its own right.

Standalone, not extends SJToggleButton

SJCheckBox stands alone over Checkbox + AbstractButtonMixin rather than extending SJToggleButton, and duplicates the Checkbox-peer toggle surface: SJToggleButton peers over a Button for pressed chrome (SD_sjtogglebutton_button_peer), so there is no shared Checkbox-peer basis to inherit. Same parallel-not-shared duplication SJRadioButton carries (SD_sjpasswordfield) — Vaadin Checkbox, Button, and our VaadinRadioButton share no ancestor below Component, so a toggle over each needs its own peer-bound wiring.

Override surface against AbstractButtonMixin

  • installButtonBindings() — installs JToggleButton.ToggleButtonModel (toggle semantics) and a HasValue<Boolean> ValueChangeListener (covers mouse AND keyboard-Space through one path); skips the mixin's inline-flex CSS seed (Checkbox shadow DOM doesn't honor host flex).
  • setModel(ButtonModel) — adds a model→peer push ItemListener mirroring model.isSelected() into Checkbox.setValue under preventPeerEvents.
  • setText(String) / getText() — Checkbox is HasLabel, not HasText; route through setLabel/getLabel, normalise null → "" (R_vaadin_first lossy).
  • Layout setters — validate per R_match_swing_errors (IAE on invalid SwingConstants) then drop-and-WARN on non-default; shadow DOM doesn't honor host inline-flex, so silent CSS would deceive.
  • setEnabled(boolean) — explicit redirect into the mixin chain, so the choice is pinned in source rather than resting on interface-default specificity.
  • setIcon — not overridden. The mixin's default WARN-drops on the non-Button branch (Checkbox has no icon slot).

JCheckBox-specific surface

borderPaintedFlat (drop-and-WARN per R_vaadin_first — no Vaadin counterpart), getUIClassID() == "CheckBoxUI", and the JCheckBox paramString tail. The emulator-side :emulators.JCheckBox keeps its own borderPaintedFlat field + PCE for full JDK round-trip per R_swing_is_truth.

Browser-originated toggle wiring

The ValueChangeListener guards on preventPeerEvents (echo from our own push) and model.isSelected() == newValue (idempotency), then funnels through SHelper.callSwing(Runnable) (this::synthesizePeerClick) so user-click and doClick deliver identical Item + Change + Action sequences.
See Also:
  • Constructor Details

    • SJCheckBox

      public SJCheckBox()
    • SJCheckBox

      public SJCheckBox(String text)
    • SJCheckBox

      public SJCheckBox(String text, boolean selected)
    • SJCheckBox

      public SJCheckBox(Icon icon)
    • SJCheckBox

      public SJCheckBox(Icon icon, boolean selected)
    • SJCheckBox

      public SJCheckBox(String text, Icon icon)
    • SJCheckBox

      public SJCheckBox(String text, Icon icon, boolean selected)
    • SJCheckBox

      public SJCheckBox(Action action)
  • Method Details

    • validate

      public void validate()
      Visibility-widening override required by ComponentMixin's public validate() contract — Vaadin Checkbox declares the inherited validate() as protected (input validation, not Swing's layout cycle). Same SD_toggle_checkbox_first_cut / SD_sjtextfield / SD_sjpasswordfield precedent; delegates to Checkbox's super.
      Specified by:
      validate in interface ComponentMixin
      Overrides:
      validate in class com.vaadin.flow.component.checkbox.Checkbox
    • installButtonBindings

      public void installButtonBindings()
      Override of the mixin's default: JToggleButton.ToggleButtonModel as default model, a HasValue<Boolean> ValueChangeListener (covers mouse-click AND keyboard-Space without double-firing) instead of the ClickNotifier wire, and skips the inline-flex CSS seed (Checkbox shadow DOM doesn't honor host flex). Idempotent.
      Specified by:
      installButtonBindings in interface AbstractButtonMixin
    • setModel

      public void setModel(ButtonModel newModel)
      Override of AbstractButtonMixin.setModel(ButtonModel) to additionally install a model→peer push ItemListener that mirrors model.isSelected() into Checkbox.setValue under preventPeerEvents. Catches direct myModel.setSelected(...) mutations, not just mixin-routed ones.
      Specified by:
      setModel in interface AbstractButtonMixin
    • getText

      public String getText()
      Description copied from interface: AbstractButtonMixin
      Abstract — each concrete AbstractButton-lineage surrogate provides its own getText via the parent Vaadin component's HasText contract. SJButton's inherited Button.getText() (which reads textNode) satisfies this requirement automatically. Mixin-internal callers (e.g. AbstractButtonMixin.getActionCommand()'s text fallback, AbstractButtonMixin.setDisplayedMnemonicIndex(int)'s length validation) reach the concrete impl via virtual dispatch.

      Pulled out of the mixin's default-implementation surface so the mixin doesn't need a reentry-flag dance to call back into the parent's HasText methods — the rendered text path is owned by the concrete surrogate, end of story.

      Specified by:
      getText in interface AbstractButtonMixin
    • setText

      public void setText(String text)
      Description copied from interface: AbstractButtonMixin
      Abstract — each concrete surrogate implements via super (its Vaadin parent's HasText.setText, e.g. Button.setText → textSupport) plus the "text" PCE fire. Pulled out of the mixin's default surface for the same reason as AbstractButtonMixin.getText().
      Specified by:
      setText in interface AbstractButtonMixin
    • setEnabled

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

      Not forced by a "classes beat interfaces" shadow — Vaadin Checkbox declares no setEnabled of its own, so AbstractButtonMixin's default would win on specificity anyway. Kept to pin the choice in source, and because the sibling SButton really does need it (Vaadin Button declares one).

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

      public int getHorizontalAlignment()
      Specified by:
      getHorizontalAlignment in interface AbstractButtonMixin
    • setHorizontalAlignment

      public void setHorizontalAlignment(int alignment)
      Specified by:
      setHorizontalAlignment in interface AbstractButtonMixin
    • getVerticalAlignment

      public int getVerticalAlignment()
      Specified by:
      getVerticalAlignment in interface AbstractButtonMixin
    • setVerticalAlignment

      public void setVerticalAlignment(int alignment)
      Specified by:
      setVerticalAlignment in interface AbstractButtonMixin
    • getHorizontalTextPosition

      public int getHorizontalTextPosition()
      Specified by:
      getHorizontalTextPosition in interface AbstractButtonMixin
    • setHorizontalTextPosition

      public void setHorizontalTextPosition(int pos)
      Specified by:
      setHorizontalTextPosition in interface AbstractButtonMixin
    • getVerticalTextPosition

      public int getVerticalTextPosition()
      Specified by:
      getVerticalTextPosition in interface AbstractButtonMixin
    • setVerticalTextPosition

      public void setVerticalTextPosition(int pos)
      Specified by:
      setVerticalTextPosition in interface AbstractButtonMixin
    • getIconTextGap

      public int getIconTextGap()
      Description copied from interface: AbstractButtonMixin
      Reads CSS gap back as an int. Lossy CSS round-trip per R_vaadin_first — a gap CSS value with a non-px unit (we only ever write "Npx") would parse to the JDK default 4.
      Specified by:
      getIconTextGap in interface AbstractButtonMixin
    • setIconTextGap

      public void setIconTextGap(int gap)
      Specified by:
      setIconTextGap in interface AbstractButtonMixin
    • getMargin

      public Insets getMargin()
      Description copied from interface: AbstractButtonMixin
      JDK default is null; no Vaadin counterpart.
      Specified by:
      getMargin in interface AbstractButtonMixin
    • setBorderPaintedFlat

      public void setBorderPaintedFlat(boolean b)
      R_vaadin_first drop-and-WARN. Vaadin Checkbox owns its chrome — no counterpart for "paint border only when in toolbar". Default false is silent; true WARNs and drops. No PCE (no state, no change).
    • isBorderPaintedFlat

      public boolean isBorderPaintedFlat()
      Returns the JDK default; no shadow store per R_vaadin_first.
    • getUIClassID

      public String getUIClassID()
      Description copied from interface: JComponentMixin
      Deliberate no-op — L&F key.
      Specified by:
      getUIClassID in interface AbstractButtonMixin
      Specified by:
      getUIClassID in interface JComponentMixin
    • paramString

      protected String paramString()
      JDK JCheckBox.paramString appends ",borderPaintedFlat=<bool>". We always report false (the JDK default) since the surrogate doesn't store the value per R_vaadin_first.
    • getAccessibleContext

      public AccessibleContext getAccessibleContext()