Class SJToggleButton

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.button.Button
com.vaadin.swingbridge.surrogates.SJToggleButton
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<com.vaadin.flow.component.button.Button>, com.vaadin.flow.component.ClickNotifier<com.vaadin.flow.component.button.Button>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<com.vaadin.flow.component.button.Button>, com.vaadin.flow.component.FocusNotifier<com.vaadin.flow.component.button.Button>, com.vaadin.flow.component.HasAriaLabel, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasText, com.vaadin.flow.component.HasTheme, com.vaadin.flow.component.shared.HasPrefix, com.vaadin.flow.component.shared.HasSuffix, com.vaadin.flow.component.shared.HasThemeVariant<com.vaadin.flow.component.button.ButtonVariant>, com.vaadin.flow.component.shared.HasTooltip, ComponentMixin, ContainerMixin, AbstractButtonMixin, JComponentMixin, ItemSelectable, Serializable

@StyleSheet("emul/sjtogglebutton.css") public class SJToggleButton extends com.vaadin.flow.component.button.Button implements AbstractButtonMixin
Surrogate for JToggleButton (SD_sjtogglebutton_button_peer). Extends Vaadin Button directly (is-a), rendering a stays-pressed button — JToggleButton's actual Swing look — rather than a checkbox glyph. Reaches the migrator either through :emulators.JToggleButton as peer, or as a richer-than-stock Vaadin toggle in its own right.
SJToggleButton bold = new SJToggleButton("Bold");
bold.addItemListener(e -> font.bold = e.getStateChange() == ItemEvent.SELECTED);
// browser click -> Button ClickEvent -> ToggleButtonModel pulse ->
//                  Item + Change + Action, and aria-pressed flips.

Button peer vs. the Checkbox-family toggles

SJCheckBox / SJRadioButton peer over HasValue<Boolean> widgets (Checkbox / radio) and render a glyph; this one peers over Button, which is not HasValue. That single difference drives every divergence from those siblings:
  • Browser wire is ClickNotifier, not ValueChange. A Button emits ClickEvent; there is no boolean value to listen on. So the mixin's default ClickNotifier wire fits — installButtonBindings() only swaps the default model for JToggleButton.ToggleButtonModel so press→release-while-armed toggles selected and fires Item + Change + Action.
  • Selection shows as an aria-pressed attribute + CSS, not a checked box. The setModel(ButtonModel) push wire mirrors model.isSelected() onto the aria-pressed host attribute; emul/sjtogglebutton.css paints the depressed look off it. No feedback-loop guard is needed (unlike the Checkbox siblings' preventPeerEvents) because writing an attribute doesn't echo back as a ClickEvent.
  • Layout + icon bind for real, inherited straight from AbstractButtonMixin: Button's host is display: inline-flex per Lumo, so alignment / text-position / iconTextGap write host CSS and read back, and setIcon hits the mixin's Vaadin-first Button branch. The Checkbox siblings drop-and-WARN these (shadow DOM won't honor host flex, no icon slot) — this surrogate doesn't.
  • setText routes through Button's HasText (SJButton shape) — Button is texted, not labelled.

ButtonGroup mutex lives at the emulator layer (D_buttongroup_browser_click)

The surrogate carries no ButtonGroup awareness — standalone, a click toggles on/off via the ToggleButtonModel pulse. Stage-3 group mutex uses :emulators.JToggleButton + vaadinx.swing.ButtonGroup per D_buttongroup: the emulator hands this surrogate a model whose setSelected consults the group (D_emulator_button_model).
See Also:
  • Constructor Details

    • SJToggleButton

      public SJToggleButton()
    • SJToggleButton

      public SJToggleButton(String text)
    • SJToggleButton

      public SJToggleButton(String text, boolean selected)
    • SJToggleButton

      public SJToggleButton(Icon icon)
    • SJToggleButton

      public SJToggleButton(Icon icon, boolean selected)
    • SJToggleButton

      public SJToggleButton(String text, Icon icon)
    • SJToggleButton

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

      public SJToggleButton(Action action)
  • Method Details

    • installButtonBindings

      public void installButtonBindings()
      Override of the mixin's default: the sole change is installing JToggleButton.ToggleButtonModel (toggle-on-release) instead of DefaultButtonModel (momentary). The ClickNotifier wire and inline-flex CSS seed are identical to the default — Button is a ClickNotifier and honors host flex — so both are kept. Idempotent: a no-op once model is installed.
      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() onto the aria-pressed host attribute. Catches direct myModel.setSelected(...) mutations as well as mixin-routed ones. Tracks teardown in peerSyncRegistration so a subsequent setModel swap detaches cleanly.
      Specified by:
      setModel 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
      Specified by:
      setText in interface com.vaadin.flow.component.HasText
      Overrides:
      setText in class com.vaadin.flow.component.button.Button
    • setEnabled

      public void setEnabled(boolean enabled)
      Java "classes beat interfaces" shadows the mixin chain's setEnabled (SD_auto_pce auto-PCE + model propagation) with Vaadin HasEnabled's default. Redirect explicitly so the mixin chain runs — matters because ToggleButtonModel's setPressed short-circuits when disabled.
      Specified by:
      setEnabled in interface ComponentMixin
      Specified by:
      setEnabled in interface com.vaadin.flow.component.HasEnabled
      Specified by:
      setEnabled in interface JComponentMixin
      Overrides:
      setEnabled in class com.vaadin.flow.component.button.Button
    • 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 JToggleButton's paramString is essentially empty (returns AbstractButton's). We skip the AbstractButton.paramString chain (Vaadin's Component.toString is the honest host-side equivalent) and report nothing extra.
    • getAccessibleContext

      public AccessibleContext getAccessibleContext()