Class SCheckbox
java.lang.Object
com.vaadin.flow.component.Component
- 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 Why not
The mixin already owns
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'ssetState 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 groupedjava.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:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.vaadin.flow.component.checkbox.Checkbox
com.vaadin.flow.component.checkbox.Checkbox.CheckboxI18nNested classes/interfaces inherited from class com.vaadin.flow.component.AbstractField
com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<C,V> Nested classes/interfaces inherited from interface com.vaadin.flow.component.BlurNotifier
com.vaadin.flow.component.BlurNotifier.BlurEvent<C>Nested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifier
com.vaadin.flow.component.FocusNotifier.FocusEvent<C>Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasValue
com.vaadin.flow.component.HasValue.ValueChangeEvent<V>, com.vaadin.flow.component.HasValue.ValueChangeListener<E> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidObject[]booleangetState()booleanprotected StringAWT'sCheckbox.paramStringomits the label clause when null.protected voidAWT's dispatch hook.voidvoidsetEnabled(boolean enabled) Routes into the mixin chain so SD_auto_pce's auto-PCE fires.voidNever mix withsetLabelComponent— Vaadin'ssetLabelevicts a label component child.voidsetRadioLook(boolean radioLook) Switches between the checkbox and radio glyphs.voidsetState(boolean state) Fires noItemEvent— AWT's programmatic setter is silent.voidvalidate()WidensCheckbox.validate()to public so the mixin'svalidate()contract is satisfied — a class member beats an interface default, and narrowing the visibility would not compile.Methods inherited from class com.vaadin.flow.component.checkbox.Checkbox
bindIndeterminate, getAriaDescribedBy, getAriaLabel, getAriaLabelledBy, getDefaultValidator, getI18n, getLabel, isAutofocus, isIndeterminate, isRequiredIndicatorVisible, setAriaDescribedBy, setAriaLabel, setAriaLabelledBy, setAutofocus, setI18n, setIndeterminate, setLabelComponent, setManualValidation, setRequiredIndicatorVisibleMethods inherited from class com.vaadin.flow.component.AbstractSinglePropertyField
getSynchronizationRegistration, hasValidValue, setPresentationValue, setSynchronizedEventMethods inherited from class com.vaadin.flow.component.AbstractField
addValueChangeListener, bindValue, getEmptyValue, getValue, isEmpty, setModelValue, setValue, valueEqualsMethods inherited from class com.vaadin.flow.component.Component
addListener, bindVisible, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTestId, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setTestId, setVisible, whenAttachedMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.BlurNotifier
addBlurListenerMethods inherited from interface com.vaadin.flow.component.ClickNotifier
addClickListener, addClickShortcut, addDoubleClickListener, addSingleClickListenerMethods inherited from interface ComponentMixin
_installSwingClass, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, dispatchEvent, doLayout, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getComponentListeners, getCursor, getFocusListeners, getFont, getForeground, getGraphics, getHierarchyBoundsListeners, getHierarchyListeners, getKeyListeners, getLocation, getMaximumSize, getMinimumSize, getMouseListeners, getName, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolTipText, getX, getY, grabFocus, hasFocus, invalidate, isDisplayable, isFocusable, isFocusOwner, isShowing, paint, paintAll, print, printAll, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, revalidate, setBackground, setBounds, setBounds, setCursor, setFocusable, setFont, setForeground, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setToolTipText, transferFocus, transferFocusBackward, transferFocusUpCycle, updateMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.Focusable
addFocusShortcut, blur, focus, focus, getTabIndex, setTabIndexMethods inherited from interface com.vaadin.flow.component.FocusNotifier
addFocusListenerMethods inherited from interface com.vaadin.flow.component.HasAriaDescription
setAriaDescribedByMethods inherited from interface com.vaadin.flow.component.HasAriaLabel
setAriaLabelledByMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
bindEnabled, isEnabledMethods inherited from interface com.vaadin.flow.component.HasHelper
bindHelperText, getHelperComponent, getHelperText, setHelperComponent, setHelperTextMethods inherited from interface com.vaadin.flow.component.HasSize
bindHeight, bindWidth, getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFullMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, bindClassName, bindClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameMethods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, bindThemeName, bindThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeNameMethods inherited from interface com.vaadin.flow.component.shared.HasThemeVariant
addThemeVariants, bindThemeVariant, bindThemeVariants, removeThemeVariants, setThemeVariant, setThemeVariants, setThemeVariantsMethods inherited from interface com.vaadin.flow.component.shared.HasTooltip
getTooltip, setTooltipMarkdown, setTooltipTextMethods inherited from interface com.vaadin.flow.component.shared.HasValidationProperties
getErrorMessage, isInvalid, setErrorMessage, setInvalidMethods inherited from interface com.vaadin.flow.data.binder.HasValidator
addValidationStatusChangeListenerMethods inherited from interface com.vaadin.flow.component.HasValue
addValueChangeListener, bindValue, clear, getEmptyValue, getOptionalValue, getValue, isEmpty, setValueMethods inherited from interface com.vaadin.flow.component.HasValueAndElement
bindReadOnly, bindRequiredIndicatorVisible, isReadOnly, setReadOnly
-
Constructor Details
-
SCheckbox
public SCheckbox() -
SCheckbox
-
SCheckbox
- 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 noItemEvent— AWT's programmatic setter is silent. -
getSelectedObjects
- Specified by:
getSelectedObjectsin interfaceItemSelectable- Returns:
- a one-element array holding the label when checked, else null —
AWT's convention here, which
java.awt.Listdoes not share (it answers an empty array)
-
setLabel
Never mix withsetLabelComponent— Vaadin'ssetLabelevicts a label component child.- Specified by:
setLabelin interfacecom.vaadin.flow.component.HasLabel- Overrides:
setLabelin classcom.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 AWTCheckboxGroupimplies is the emulator's job.- Parameters:
radioLook- DOM-backed via theemul-radiotheme name, so the round-trip is lossless and no field shadow is needed
-
addItemListener
- Specified by:
addItemListenerin interfaceItemSelectable
-
removeItemListener
- Specified by:
removeItemListenerin interfaceItemSelectable
-
getItemListeners
-
processItemEvent
AWT's dispatch hook. Overriding it (and calling super) is the documented way forjava.awt.Checkboxsubclasses 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
Checkboxdeclares nosetEnabled, soComponentMixin's default wins on specificity anyway. Kept to pin the choice in source, asSJCheckBoxdoes.- Specified by:
setEnabledin interfaceComponentMixin- Specified by:
setEnabledin interfacecom.vaadin.flow.component.HasEnabled
-
validate
public void validate()WidensCheckbox.validate()to public so the mixin'svalidate()contract is satisfied — a class member beats an interface default, and narrowing the visibility would not compile.- Specified by:
validatein interfaceComponentMixin- Overrides:
validatein classcom.vaadin.flow.component.checkbox.Checkbox
-
paramString
AWT'sCheckbox.paramStringomits the label clause when null. -
getAccessibleContext
-