Class JComboBox<E>
- All Implemented Interfaces:
ActionListener, ImageObserver, ItemSelectable, MenuContainer, Serializable, EventListener, Accessible, ListDataListener, FieldReconciler.Reconcilable
JComboBox, rendered by SJComboBox (SD_sjcombobox).
R_leaf_peer_lockdown-locked-down: JComboBox is a leaf in the public
javax.swing.* hierarchy, so the protected (Component peer)
ctor is omitted and the root public ctor hard-codes the surrogate.
The event engine is the JDK's, and it lives here, as it does in the JDK: this combo is
its model's ListDataListener, and contentsChanged(ListDataEvent) /
intervalAdded(ListDataEvent) / intervalRemoved(ListDataEvent) fire the ItemEvent pair and the
ActionEvent. So a worker filling the model hears the events on the worker, and every
getter reads the model or a Swing-side field, never the peer. The surrogate listens to the
same model and renders it. It keeps its own listener lists for stage-3 code, which this
emulator does not subscribe to. A browser pick reaches the model through the surrogate and
comes back here as a model event. isPopupVisible() is the one piece of state the
browser also changes: setPopupVisible(boolean) writes it and fires the popup events itself,
and a user's click reaches it through the surrogate's
SJComboBox.addOpenedChangeListener(ComponentEventListener). The
ListCellRenderer carve-out (D_jcombobox) is documented on setRenderer(ListCellRenderer).
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceThe JDK's nested interface, ported so a migratednew JComboBox.KeySelectionManager() { … }still compiles after the import swap. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringprotected ComboBoxModel<E> protected Objectprotected booleanprotected JComboBox.KeySelectionManagerprotected booleanprotected intprotected ListCellRenderer<? super E> protected ObjectFields inherited from class JComponent
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields 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 TypeMethodDescriptionvoidJDK JComboBox implements ActionListener so it can register itself as the editor's ActionListener for editable combo boxes.voidvoidvoidaddItemListener(ItemListener aListener) voidvoidconfigureEditor(Object anEditor, Object anItem) protected voidvoidThe model's selection or contents changed: theItemEventpair, then theActionEventunlesssetSelectedItem(Object)is firing it.protected PropertyChangeListenerprotected voidNotifies theActionListeners last to first, as the JDK does; a listener re-entering it fires nothing.protected voidvoidNever reached by SB-Emulators itself; seeinstallOpenedSync(SJComboBox).voidvoidgetItemAt(int index) intintgetModel()ListCellRenderer<? super E> intObject[]getUI()voidvoidinsertItemAt(E item, int index) voidAn added element can change the selection (a first element becomes selected); noActionEvent.voidbooleanbooleanbooleanWhether the dropdown is open, whether the program or the user opened it.final voidD_field_write_reconcile repair hook — seeJSlider.reconcileFields().voidvoidThe JDK also clears an editable combo's editor; the editor here is inert (seesetEditor(Object)), so that step is the declined effect.voidremoveItem(Object anObject) voidremoveItemAt(int anIndex) voidremoveItemListener(ItemListener aListener) voidprotected voidFires theItemEventpair for a selection change:DESELECTEDon the old item andSELECTEDon the new one, each only when non-null.booleanselectWithKeyChar(char keyChar) voidvoidsetActionCommand(String aCommand) voidsetEditable(boolean aFlag) voidStores the editor and fires"editor"; the editor is inert.voidStored but never consulted: the JDK reaches a manager only throughselectWithKeyChar, which its L&F calls on a keystroke, and here type-to-select is the browser's own — avaadin-combo-boxfilters on typing and no keystroke reaches the server as a char.voidsetLightWeightPopupEnabled(boolean aFlag) Stores the flag and fires"lightWeightPopupEnabled".voidsetMaximumRowCount(int count) voidsetModel(ComboBoxModel<E> aModel) voidsetPopupVisible(boolean v) Open or close the dropdown.voidsetPrototypeDisplayValue(E prototypeDisplayValue) Stores the prototype and fires"prototypeDisplayValue"; no sizing happens.voidsetRenderer(ListCellRenderer<? super E> r) Install a JDK-shapedListCellRendereron this combo.voidsetSelectedIndex(int anIndex) voidsetSelectedItem(Object anObject) SelectsanObject, rejecting one the model does not contain unless the combo box is editable, and fires theActionEventonce whether or not the selection changed, as the JDK does.voidsetUI(ComboBoxUI ui) voidvoidupdateUI()Methods inherited from class JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateMethods inherited from class Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, addSlotChild, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, fireHierarchyEvent, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, peerContentElement, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeSlotChild, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeMethods inherited from class Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, applyBackgroundToPeer, applyVisibleToPeer, awtListeners, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, defaultFillCssClass, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, fireComponentEvent, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isThemeDefault, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, suppressMouseBridge, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, withPeer, withPeerOnLiveUI
-
Field Details
-
actionCommand
-
renderer
-
dataModel
-
isEditable
protected boolean isEditable -
maximumRowCount
protected int maximumRowCount -
selectedItemReminder
-
editor
-
lightWeightPopupEnabled
protected boolean lightWeightPopupEnabled -
keySelectionManager
-
-
Constructor Details
-
JComboBox
public JComboBox() -
JComboBox
-
JComboBox
-
JComboBox
-
-
Method Details
-
reconcileFields
public final void reconcileFields()D_field_write_reconcile repair hook — seeJSlider.reconcileFields().- Specified by:
reconcileFieldsin interfaceFieldReconciler.Reconcilable
-
setSelectedItem
SelectsanObject, rejecting one the model does not contain unless the combo box is editable, and fires theActionEventonce whether or not the selection changed, as the JDK does. On a match, the model's own element is selected, so anequals-but-not-==argument does not displace it.The JDK also hands a matched item to
getEditor().setItem; the editor here is inert (seesetEditor(Object)), so that step is the declined effect. -
getSelectedItem
-
getSelectedIndex
public int getSelectedIndex() -
setSelectedIndex
public void setSelectedIndex(int anIndex) -
getSelectedObjects
- Specified by:
getSelectedObjectsin interfaceItemSelectable
-
addItem
-
insertItemAt
-
removeItem
-
removeItemAt
public void removeItemAt(int anIndex) -
removeAllItems
public void removeAllItems()The JDK also clears an editable combo's editor; the editor here is inert (seesetEditor(Object)), so that step is the declined effect. -
getItemAt
-
getItemCount
public int getItemCount() -
getModel
-
setModel
-
isEditable
public boolean isEditable() -
setEditable
public void setEditable(boolean aFlag) -
isPopupVisible
public boolean isPopupVisible()Whether the dropdown is open, whether the program or the user opened it. -
setPopupVisible
public void setPopupVisible(boolean v) Open or close the dropdown. Opening firespopupMenuWillBecomeVisibleevery time, even on an open dropdown; closing firespopupMenuWillBecomeInvisibleonly when it was open. Both fire before the state changes.The notifications are the Basic L&F's, which every stock L&F inherits:
BasicComboPopup.show()fires unconditionally and then asks forgetLocationOnScreen(), whosegetLocationOnScreen_NoTreeLockthrows unlesspeer != null && isShowing()(message reproduced verbatim), whilehide()reachesJPopupMenu.setVisible(false), which returns early on a hidden popup. The hide path never asks for a location, sosetPopupVisible(false)stays silent on a combo box that was never shown.- Throws:
IllegalComponentStateException- on an opening call for a combo box that is not showing, afterpopupMenuWillBecomeVisiblehas fired — the same failure a real JComboBox produces for the same call, per R_match_swing_errors' match-Swing's-error-handling clause.
-
showPopup
public void showPopup() -
hidePopup
public void hidePopup() -
getMaximumRowCount
public int getMaximumRowCount() -
setMaximumRowCount
public void setMaximumRowCount(int count) -
addItemListener
- Specified by:
addItemListenerin interfaceItemSelectable
-
removeItemListener
- Specified by:
removeItemListenerin interfaceItemSelectable
-
getItemListeners
-
fireItemStateChanged
-
selectedItemChanged
protected void selectedItemChanged()Fires theItemEventpair for a selection change:DESELECTEDon the old item andSELECTEDon the new one, each only when non-null. -
addActionListener
-
removeActionListener
-
getActionListeners
-
setActionCommand
-
getActionCommand
-
fireActionEvent
protected void fireActionEvent()Notifies theActionListeners last to first, as the JDK does; a listener re-entering it fires nothing.The JDK copies the modifiers of
EventQueue.getCurrentEvent(); no AWT event is being dispatched here, so they are 0. -
actionPerformed
JDK JComboBox implements ActionListener so it can register itself as the editor's ActionListener for editable combo boxes. The default body fires the combo's own ActionEvent — which is what happens here too.- Specified by:
actionPerformedin interfaceActionListener
-
addPopupMenuListener
-
removePopupMenuListener
-
getPopupMenuListeners
-
firePopupMenuWillBecomeVisible
public void firePopupMenuWillBecomeVisible() -
firePopupMenuWillBecomeInvisible
public void firePopupMenuWillBecomeInvisible() -
firePopupMenuCanceled
public void firePopupMenuCanceled()Never reached by SB-Emulators itself; seeinstallOpenedSync(SJComboBox). -
contentsChanged
The model's selection or contents changed: theItemEventpair, then theActionEventunlesssetSelectedItem(Object)is firing it.- Specified by:
contentsChangedin interfaceListDataListener
-
intervalAdded
An added element can change the selection (a first element becomes selected); noActionEvent.- Specified by:
intervalAddedin interfaceListDataListener
-
intervalRemoved
- Specified by:
intervalRemovedin interfaceListDataListener
-
getRenderer
-
setRenderer
Install a JDK-shapedListCellRendereron this combo. The bridge wraps the renderer in a VaadinComponentRendererthat, per item, callsrenderer.getListCellRendererComponent(null, item, index, false, false)and snapshots the resulting emulator component's rendered state into a fresh VaadinSpanbefore returning it. The snapshot is required because the JDK renderer pattern is mutate-and-return-self: the sameJLabelinstance is reconfigured and returned on every call. Vaadin'sComponentRendererrequires a freshComponentper item — adopting the same DOM node into multiple positions silently fails on all but the last (only the last assignment "wins"; earlier rows render empty).The snapshot covers:
- Text (always) — read from
JLabel.getText()and applied to the fresh Span. - Icon (
ImageIcononly — Path 1 per D_icon_rendering) — read fromJLabel.getIcon()and bridged to a VaadinImagechild via the existingcom.vaadin.swingbridge.surrogates.util.Icons.imageIconToVaadinImage. OtherIconimpls drop with a WARN (Path 2/3 deferred).
Limitation: renderer must be JLabel-shaped.
DefaultListCellRenderer+ subclasses (the typical migration pattern) work directly. Renderers that return aJPanelor other deeper component tree fall back to a Span withString.valueOf(value)and emit a WARN — the JDK mutate-and-return-self contract doesn't generalise to fresh-per-call without per-renderer snapshot logic, and we don't ship one for arbitrary subtrees. R_match_swing_errors sub-bucket (a) gap.The
listargument is alwaysnull,isSelectedandcellHasFocusalwaysfalse— Vaadin's render pipeline doesn't surface those at render time and our combo box doesn't model a JList yet (D_jcombobox).indexis reconstructed by scanning the model for the item — O(n) per render, accepted for typical CRUD-shape dropdowns. - Text (always) — read from
-
getAction
-
setAction
-
configurePropertiesFromAction
-
createActionPropertyChangeListener
-
getEditor
-
setEditor
Stores the editor and fires"editor"; the editor is inert. A Vaadin ComboBox renders its own input, so there is no slot to host aComboBoxEditor's component and noActionListenerrewiring to do — the declined effect. State and notification are owed regardless (R_decline_effect_only, D_owed_events). -
configureEditor
-
getKeySelectionManager
- Returns:
nullunlesssetKeySelectionManager(JComboBox.KeySelectionManager)installed one, as in the JDK
-
setKeySelectionManager
Stored but never consulted: the JDK reaches a manager only throughselectWithKeyChar, which its L&F calls on a keystroke, and here type-to-select is the browser's own — avaadin-combo-boxfilters on typing and no keystroke reaches the server as a char. So an installed manager is state whose effect is the browser's, and the WARN says so. -
isLightWeightPopupEnabled
public boolean isLightWeightPopupEnabled()- Returns:
- what
setLightWeightPopupEnabled(boolean)stored; Swing's default istrue
-
setLightWeightPopupEnabled
public void setLightWeightPopupEnabled(boolean aFlag) Stores the flag and fires"lightWeightPopupEnabled". The distinction it draws — a lightweight in-hierarchy popup vs. a heavyweight native window — has no browser counterpart at all; the overlay is what it is. State and notification are owed regardless (R_decline_effect_only, D_owed_events). -
getPrototypeDisplayValue
-
setPrototypeDisplayValue
Stores the prototype and fires"prototypeDisplayValue"; no sizing happens. The prototype exists to let Swing size the popup from one value instead of measuring every row — a pixel-measurement concern with no counterpart here (R_layouts_close_enough). State and notification are owed regardless (R_decline_effect_only, D_owed_events). -
selectWithKeyChar
public boolean selectWithKeyChar(char keyChar) -
getUIClassID
- Overrides:
getUIClassIDin classJComponent
-
updateUI
public void updateUI()- Overrides:
updateUIin classJComponent
-
getUI
- Overrides:
getUIin classJComponent
-
setUI
-
getAccessibleContext
- Specified by:
getAccessibleContextin interfaceAccessible- Overrides:
getAccessibleContextin classComponent
-