Class List
- All Implemented Interfaces:
ImageObserver, ItemSelectable, MenuContainer, Serializable, Accessible
List — the AWT 1.0 scrolling list box, not
JList. Holds the JDK's items and selection itself, so
every getter answers on any thread without reaching the
SList peer, which renders them:
List planets = new List(4, false);
planets.add("Mercury");
planets.add("Venus");
planets.addItemListener(e -> show((Integer) e.getItem())); // payload is the INDEX
planets.addActionListener(e -> open(e.getActionCommand())); // double-click / Enter
planets.select(1); // silent: no ItemEvent
The selection follows two rule sets, as in the JDK
Until the list is displayable — added to a frame that has been packed or shown — the JDK's own bodies run:select appends to the selection
array, an insert or remove leaves the selected indexes where they were (so
they may now name other rows, or none), and flipping multi → single keeps
every selected index. Once it is displayable, the platform peer's rules
run: the selection shifts with inserts and removes, stays sorted in
multiple mode, and a multi → single flip keeps only the row that had the
location cursor. Both are reproduced; the peer's are XListPeer's.
Leaf peer is locked down per R_leaf_peer_lockdown: no public class in java.awt
extends java.awt.List, so there is no protected
(Component peer) ctor and every instance — including a user-code
subclass — peers over an SList.
The two event payloads differ, and both trip people up.
ItemEvent.getItem() is an Integer index
(unlike Choice, which posts the item String),
while ActionEvent.getActionCommand() is the item
text. And an ItemEvent always means "the user
picked something": every mutator and both selection methods are
silent, which is the inverse of JList.
- 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 TypeMethodDescriptionvoidvoidvoidvoidDeprecated.voidDeprecated.replaced byadd(String, int)— but this is the implementation, not the wrappervoidvoidbooleanDeprecated.as of JDK 1.1, replaced byisMultipleMode()— but this is the implementationvoidclear()Deprecated.as of JDK 1.1, replaced byremoveAll()— but this is the implementationintDeprecated.as of JDK 1.1, replaced bygetItemCount()— but this is the implementation, not the wrappervoiddelItem(int position) Deprecated.replaced byremove(int)— but this is on the invoked pathvoiddelItems(int start, int end) Deprecated.as of JDK 1.1, and the JDK's own note says it is expected to become package-private — but it is public today and is the implementation, not the wrappervoiddeselect(int index) Deselects a row; fires nothing.getItem(int index) intDelegates tocountItems(), not the other way round — the JDK's direction, so a subclass overriding the deprecated name stays on the invoked path (R_no_vaadin_in_api limb 2).String[]getItems()getMinimumSize(int rows) getPreferredSize(int rows) intgetRows()intint[]String[]Object[]intbooleanisIndexSelected(int index) booleanbooleanisSelected(int index) Deprecated.as of JDK 1.1, replaced byisIndexSelected(int)— but this is the implementationvoidmakeVisible(int index) Scrolls the row into view.Deprecated.as of JDK 1.1, replaced bygetMinimumSize()minimumSize(int rows) Deprecated.as of JDK 1.1, replaced bygetMinimumSize(int)protected StringDeprecated.as of JDK 1.1, replaced bygetPreferredSize()preferredSize(int rows) Deprecated.as of JDK 1.1, replaced bygetPreferredSize(int)protected voidThe double-click / Enter twin ofprocessItemEvent(ItemEvent).protected voidprotected voidThe single funnel every selection reaches its listeners through — both the peer bridge and a user-codeprocessEventcall.voidremove(int position) voidRemoves the first occurrence.voidvoidvoidvoidvoidreplaceItem(String newValue, int index) Replaces the item atindex.voidselect(int index) Selects a row.voidsetMultipleMode(boolean b) Flips multi-selection at runtime; fires nothing.voidsetMultipleSelections(boolean b) Deprecated.as of JDK 1.1, replaced bysetMultipleMode(boolean)— but this is the implementation, and it holds the no-change guardMethods 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, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, 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, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, peerIs, postEvent, prepareImage, prepareImage, print, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, 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
-
List
- Throws:
HeadlessException- never in practice — the clause is kept for signature fidelity, matchingFrame
-
List
- Throws:
HeadlessException- never in practice
-
List
- Parameters:
rows-0means four; anything else is kept verbatim, negatives included, and there is nosetRows- Throws:
HeadlessException- never in practice
-
-
Method Details
-
addNotify
-
removeNotify
public void removeNotify()- Overrides:
removeNotifyin classComponent
-
getItemCount
public int getItemCount()Delegates tocountItems(), not the other way round — the JDK's direction, so a subclass overriding the deprecated name stays on the invoked path (R_no_vaadin_in_api limb 2). Every pair below runs the same way. -
countItems
Deprecated.as of JDK 1.1, replaced bygetItemCount()— but this is the implementation, not the wrapper -
getItem
- Throws:
ArrayIndexOutOfBoundsException- when out of range, as AWT's backingVectordoes (R_match_swing_errors)
-
getItems
- Returns:
- a fresh array; the receiver is untouched
-
add
-
addItem
Deprecated.replaced byadd(String)— but this is on the invoked path -
add
- Parameters:
index- anything outside[0, getItemCount())appends, with no exception — including-1, the documented "append"
-
addItem
Deprecated.replaced byadd(String, int)— but this is the implementation, not the wrapperThe one insert body everyaddreaches, coercions included: an out-of-range index appends and a null item becomes"", so no insert ever throws. -
replaceItem
Replaces the item atindex.The JDK body is literally
remove(index); add(newValue, index);, both public, so a subclass overriding either intercepts this too. Kept as the two calls rather than a direct peer replace, which would break that (R_no_vaadin_in_api limb 2). A side effect falls out of it: on a displayed list the replaced row loses its selection.- Throws:
ArrayIndexOutOfBoundsException- when out of range — raised by theremovehalf, before anything is added
-
removeAll
public void removeAll() -
clear
Deprecated.as of JDK 1.1, replaced byremoveAll()— but this is the implementation -
remove
Removes the first occurrence.- Throws:
IllegalArgumentException- when the item is not in the list, with the JDK's own message (R_match_swing_errors)
-
remove
public void remove(int position) - Throws:
ArrayIndexOutOfBoundsException- when out of range, as AWT'sVector.removeElementAtdoes (R_match_swing_errors)
-
delItem
Deprecated.replaced byremove(int)— but this is on the invoked path -
delItems
Deprecated.as of JDK 1.1, and the JDK's own note says it is expected to become package-private — but it is public today and is the implementation, not the wrapperThe one delete body everyremovereaches.- Throws:
ArrayIndexOutOfBoundsException- when the range leaves the list — and note the JDK's loop runs downwards fromend, so a negativestartremoves the higher indices first and only then throws, leaving the list shorter. Reproduced. Anendpast the top throws with nothing removed.
-
getSelectedIndex
public int getSelectedIndex()- Returns:
- the sole selected index, or
-1when nothing or more than one thing is selected. Not "the first selected index"
-
getSelectedIndexes
public int[] getSelectedIndexes()- Returns:
- a copy, and a zero-length array when nothing is selected
-
getSelectedItem
- Returns:
- null when nothing, or more than one thing, is selected
-
getSelectedItems
- Returns:
- a zero-length array when nothing is selected
-
getSelectedObjects
- Specified by:
getSelectedObjectsin interfaceItemSelectable- Returns:
- an empty array when nothing is selected —
List's convention, and the opposite ofChoiceandCheckbox, which answer null
-
select
public void select(int index) Selects a row. Fires noItemEvent— the JDK's javadoc says so outright. Out of range is documented as unspecified; both of the JDK's branches store the index anyway, and so does this, sogetSelectedIndex()can answer a row that does not exist. -
deselect
public void deselect(int index) Deselects a row; fires nothing. While displayable, in single mode the call reaches the peer only whenindexis the sole selected row — the JDK's own guard. -
isIndexSelected
public boolean isIndexSelected(int index) -
isSelected
Deprecated.as of JDK 1.1, replaced byisIndexSelected(int)— but this is the implementation -
getRows
public int getRows()- Returns:
- the constructor's value verbatim —
4for the zero default, and negatives unchanged. Never changes; there is no setter
-
isMultipleMode
public boolean isMultipleMode() -
allowsMultipleSelections
Deprecated.as of JDK 1.1, replaced byisMultipleMode()— but this is the implementation -
setMultipleMode
public void setMultipleMode(boolean b) Flips multi-selection at runtime; fires nothing. Going multiple → single, a displayed list keeps the row with the location cursor if it is selected and drops the rest; a peerless one keeps them all. -
setMultipleSelections
Deprecated.as of JDK 1.1, replaced bysetMultipleMode(boolean)— but this is the implementation, and it holds the no-change guard -
getVisibleIndex
public int getVisibleIndex()- Returns:
- the last index passed to
makeVisible(int), or-1
-
makeVisible
public void makeVisible(int index) Scrolls the row into view. The index is recorded even when out of range, as in AWT. -
getPreferredSize
-
preferredSize
Deprecated.as of JDK 1.1, replaced bygetPreferredSize(int) -
getPreferredSize
- Overrides:
getPreferredSizein classComponent
-
preferredSize
Deprecated.as of JDK 1.1, replaced bygetPreferredSize()- Overrides:
preferredSizein classComponent
-
getMinimumSize
-
minimumSize
Deprecated.as of JDK 1.1, replaced bygetMinimumSize(int) -
getMinimumSize
- Overrides:
getMinimumSizein classComponent
-
minimumSize
Deprecated.as of JDK 1.1, replaced bygetMinimumSize()- Overrides:
minimumSizein classComponent
-
addItemListener
- Specified by:
addItemListenerin interfaceItemSelectable
-
removeItemListener
- Specified by:
removeItemListenerin interfaceItemSelectable
-
getItemListeners
-
addActionListener
-
removeActionListener
-
getActionListeners
-
processEvent
- Overrides:
processEventin classComponent
-
processItemEvent
The single funnel every selection reaches its listeners through — both the peer bridge and a user-codeprocessEventcall. Overriding it and calling super is AWT's documented interception idiom. -
processActionEvent
The double-click / Enter twin ofprocessItemEvent(ItemEvent). -
paramString
- Overrides:
paramStringin classComponent
-
getAccessibleContext
- Specified by:
getAccessibleContextin interfaceAccessible- Overrides:
getAccessibleContextin classComponent
-
add(String)— but this is on the invoked path