Class Choice
- All Implemented Interfaces:
ImageObserver, ItemSelectable, MenuContainer, Serializable, Accessible
Choice — the AWT 1.0 dropdown, not
JComboBox. Holds the JDK's item vector and selection
itself, so every getter answers on any thread without reaching the
SChoice peer, which renders them:
Choice units = new Choice();
units.add("metric");
units.add("imperial"); // "metric" is selected — the first add selects it
units.addItemListener(e -> recompute((String) e.getItem()));
units.select("imperial"); // silent: no ItemEvent, exactly as in AWT
The JDK class is a Vector<String> and an int: no
model, no editable mode, no renderer, no popup API and no
ActionListener. Everything a migrator touches beyond the members
below — setBounds, setFont, setEnabled,
addFocusListener, requestFocus — is inherited
Component.
The JDK's internal call directions are kept (R_no_vaadin_in_api limb 2):
the modern names delegate to the deprecated ones, an insert or remove
re-selects through the public select(int), and
getSelectedItem() reads through the public getItem(int), so an
override of any of them sees the same traffic it would on the desktop.
Leaf peer is locked down per R_leaf_peer_lockdown: java.awt.Choice
has no public subclass in java.awt, so there is no protected
(Component peer) ctor and every instance — including a user-code
subclass — peers over an SChoice.
- 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 TypeMethodDescriptionvoidAppends an item; if it is the first, it becomes selected.voidDeprecated.voidvoidintDeprecated.as of JDK 1.1, replaced bygetItemCount()— but see its note: this is the implementation, not the wrappergetItem(int index) intDelegates tocountItems(), not the other way round — that is the JDK's direction, so a subclass overriding the deprecated name stays on the invoked path (R_no_vaadin_in_api limb 2).intObject[]voidInserts atindex, shifting the rest up.protected Stringprotected voidprotected voidThe single funnel every selection reaches the listeners through — both the peer bridge and a user-codeprocessEventcall.voidremove(int position) voidRemoves the first occurrence.voidEmpties the list; the selection becomes-1, assigned directly rather than throughselect.voidvoidselect(int pos) Selects by position.voidSelects the first item equal tostr, or does nothing when there is no match — AWT is silent here, unlikeremove(String).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, 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
-
Choice
- Throws:
HeadlessException- never in practice — the clause is kept for signature fidelity, matchingFrame
-
-
Method Details
-
addNotify
-
getItemCount
public int getItemCount()Delegates tocountItems(), not the other way round — that is the JDK's direction, so a subclass overriding the deprecated name stays on the invoked path (R_no_vaadin_in_api limb 2). Inverting it would leave such an override silently dead. -
countItems
Deprecated.as of JDK 1.1, replaced bygetItemCount()— but see its note: this is the implementation, not the wrapper -
getItem
- Throws:
ArrayIndexOutOfBoundsException- when out of range, as AWT's backingVectordoes (R_match_swing_errors)
-
add
Appends an item; if it is the first, it becomes selected.Delegates to
addItem(String), the JDK's direction — same R_no_vaadin_in_api limb 2 reasoning asgetItemCount(). Note it does not route throughinsert(String, int): in the JDK both reach a private helper, so aninsertoverride does not interceptadd.- Throws:
NullPointerException- on a null item, as in AWT (R_match_swing_errors)
-
addItem
Deprecated.as of Java 2 v1.1, useadd(String)— but this is the implementation, not the wrapper -
insert
Inserts atindex, shifting the rest up.Inserting at or before the selection re-selects index 0 — the JDK comments this as "selection shifted up" but the code does not shift. Reproduced verbatim in the peer.
- Parameters:
index- clamped to the item count when too large, as in AWT- Throws:
IllegalArgumentException- on a negative index, as in AWT (R_match_swing_errors)NullPointerException- on a null item, as in AWT (R_match_swing_errors)
-
remove
Removes the first occurrence.- Throws:
IllegalArgumentException- when the item is not present, as in AWT (R_match_swing_errors) — unlikeselect(String), which is silent
-
remove
public void remove(int position) - Throws:
ArrayIndexOutOfBoundsException- when out of range, as AWT's backingVectordoes (R_match_swing_errors)
-
removeAll
public void removeAll()Empties the list; the selection becomes-1, assigned directly rather than throughselect. -
getSelectedItem
- Returns:
- null when nothing is selected, which for AWT means "no items"
-
getSelectedObjects
- Specified by:
getSelectedObjectsin interfaceItemSelectable- Returns:
- a length-1 array, or null — not an empty array — when nothing is selected. AWT's convention, the opposite of Swing's.
-
getSelectedIndex
public int getSelectedIndex() -
select
public void select(int pos) Selects by position. Fires noItemEvent— in AWT only user interaction does. AnItemEventarriving at a listener therefore always means "the user picked something", never "the program changed the selection".- Throws:
IllegalArgumentException- when out of range, as in AWT (R_match_swing_errors)
-
select
Selects the first item equal tostr, or does nothing when there is no match — AWT is silent here, unlikeremove(String). Fires noItemEvent, same asselect(int). -
addItemListener
- Specified by:
addItemListenerin interfaceItemSelectable
-
removeItemListener
- Specified by:
removeItemListenerin interfaceItemSelectable
-
getItemListeners
-
processEvent
- Overrides:
processEventin classComponent
-
processItemEvent
The single funnel every selection reaches the listeners through — both the peer bridge and a user-codeprocessEventcall. AWT subclasses override this (calling super) to intercept selections wholesale, so it must stay the only dispatch path. -
paramString
- Overrides:
paramStringin classComponent
-
getAccessibleContext
- Specified by:
getAccessibleContextin interfaceAccessible- Overrides:
getAccessibleContextin classComponent
-
add(String)— but this is the implementation, not the wrapper