Class Checkbox
- All Implemented Interfaces:
ImageObserver, ItemSelectable, MenuContainer, Serializable, Accessible
Checkbox — the AWT 1.0 checkbox, not
JCheckBox. A thin delegating shell over its
SCheckbox peer, with the
CheckboxGroup bookkeeping that turns a checkbox into a radio
button:
Checkbox verbose = new Checkbox("Verbose", false);
verbose.addItemListener(e -> setVerbose(e.getStateChange() == ItemEvent.SELECTED));
verbose.setState(true); // silent: no ItemEvent, exactly as in AWT
CheckboxGroup units = new CheckboxGroup();
new Checkbox("metric", true, units); // grouped → renders as a radio
new Checkbox("imperial", false, units);
Only the browser posts events
Every programmatic path here is silent —setState(boolean), the ctors,
setCheckboxGroup(CheckboxGroup) and every CheckboxGroup mutator. In AWT
only the toolkit posts an ItemEvent, which inverts
Swing, where AbstractButton.setSelected drives a
ButtonModel fan-out. A browser toggle posts exactly one
event, on the clicked box: the sibling a group cascade turns off gets
nothing.
Two clicks post nothing at all, both because the group vetoes the state change: unchecking the box that is its group's current selection, and re-clicking that box. Both bounce the peer back to checked.
Responsibility split with the peer:
- Surrogate — the rendered Vaadin
Checkbox, the from-client value →ItemEventfan-out, and the radio glyph (appearance only). - Emulator (here) — the AWT-shape API migrated code compiles
against, the
label/state/groupfields, and all group semantics::surrogatesknows nothing about groups (D_buttongroup_browser_click).
Leaf peer is locked down per R_leaf_peer_lockdown: java.awt.Checkbox has no
public subclass in java.awt (CheckboxMenuItem is a
MenuItem, an unrelated MenuComponent branch), so there is
no protected (Component peer) ctor and every instance peers over an
SCheckbox. The checkbox-vs-radio duality does not
force a peer seam — AWT reads the glyph off group != null at paint
time, so it is a live property of one peer, not two peer types.
- See Also:
-
Field Summary
Fields inherited from class Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, FILL_CHROME, FILL_DEFAULT, LEFT_ALIGNMENT, listenerList, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidgetLabel()Object[]booleangetState()protected Stringprotected voidprotected voidThe single funnel every toggle reaches the listeners through — both the peer bridge and a user-codeprocessEventcall.voidvoidRe-homes this box intog, switching the glyph to match.voidvoidsetState(boolean state) Sets the checked state, silently — noItemEvent, in any of the paths below.Methods inherited from class Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyBackgroundToPeer, applyComponentOrientation, applyVisibleToPeer, areFocusTraversalKeysSet, awtListeners, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, defaultFillCssClass, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, fireComponentEvent, fireHierarchyEvent, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isThemeDefault, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, peerIs, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, revalidate, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setMixingCutoutShape, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, suppressMouseBridge, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate, withPeer, withPeerOnLiveUI
-
Constructor Details
-
Checkbox
- Throws:
HeadlessException
-
Checkbox
- Throws:
HeadlessException
-
Checkbox
- Throws:
HeadlessException
-
Checkbox
- Parameters:
label- null is legal and reads back fromgetLabel()verbatimstate- a checked box joining a group makes itself that group's selection, turning off whichever box held it — silently- Throws:
HeadlessException- never in practice — the clause is kept for signature fidelity, matchingFrame
-
Checkbox
Argument order swapped; no other difference from the three-arg ctor.- Throws:
HeadlessException
-
-
Method Details
-
addNotify
-
getLabel
-
setLabel
-
getState
public boolean getState() -
setState
public void setState(boolean state) Sets the checked state, silently — noItemEvent, in any of the paths below.- Parameters:
state-falseis ignored when this box is its group's current selection: AWT upgrades it back totruerather than leaving the group with nothing selected. Passingtrueon a grouped box turns its sibling off.
-
getSelectedObjects
- Specified by:
getSelectedObjectsin interfaceItemSelectable- Returns:
- a one-element array holding the label — which may itself be
null — when checked, else null. AWT's convention here, which
java.awt.Listdoes not share (it answers an empty array)
-
getCheckboxGroup
-
setCheckboxGroup
Re-homes this box intog, switching the glyph to match.Leaves the old group with no selection at all when this box was holding it. That is AWT's behaviour and not an oversight: the clearing call runs after the box has already been re-homed, so
setCurrent's still-one-of-mine guard skips the deselect and only the pointer is dropped.- Parameters:
g- null removes the box from its group; the same group it already belongs to is an early return
-
addItemListener
- Specified by:
addItemListenerin interfaceItemSelectable
-
removeItemListener
- Specified by:
removeItemListenerin interfaceItemSelectable
-
getItemListeners
-
processEvent
- Overrides:
processEventin classComponent
-
processItemEvent
The single funnel every toggle reaches the listeners through — both the peer bridge and a user-codeprocessEventcall. AWT subclasses override this (calling super) to intercept toggles wholesale, so it must stay the only dispatch path. -
paramString
- Overrides:
paramStringin classComponent
-
getAccessibleContext
- Specified by:
getAccessibleContextin interfaceAccessible- Overrides:
getAccessibleContextin classComponent
-