Class JXComboBox
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JComboBox
-
- org.jdesktop.swingx.JXComboBox
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.awt.image.ImageObserver
,java.awt.ItemSelectable
,java.awt.MenuContainer
,java.io.Serializable
,java.util.EventListener
,javax.accessibility.Accessible
,javax.swing.event.ListDataListener
public class JXComboBox extends javax.swing.JComboBox
An enhancedJComboBox
that provides the following additional functionality:Auto-starts edits correctly for AutoCompletion when inside a
JTable
. A normalJComboBox
fails to recognize the first key stroke when it has beendecorated
.Adds highlighting support.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
JXComboBox.ComboBoxAdapter
class
JXComboBox.DelegatingRenderer
A decorator for the original ListCellRenderer.(package private) class
JXComboBox.StringValueKeySelectionManager
-
Nested classes/interfaces inherited from class javax.swing.JComboBox
javax.swing.JComboBox.AccessibleJComboBox, javax.swing.JComboBox.KeySelectionManager
-
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
-
-
Field Summary
Fields Modifier and Type Field Description private CompoundHighlighter
compoundHighlighter
private JXComboBox.ComboBoxAdapter
dataAdapter
private JXComboBox.DelegatingRenderer
delegatingRenderer
private javax.swing.event.ChangeListener
highlighterChangeListener
private boolean
isDispatching
private java.util.List<java.awt.event.KeyEvent>
pendingEvents
private StringValueRegistry
stringValueRegistry
private boolean
updatingUI
private boolean
useHighlightersForCurrentValue
-
Fields inherited from class javax.swing.JComboBox
actionCommand, dataModel, editor, isEditable, keySelectionManager, lightWeightPopupEnabled, maximumRowCount, renderer, selectedItemReminder
-
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
-
Constructor Summary
Constructors Constructor Description JXComboBox()
Creates aJXComboBox
with a default data model.JXComboBox(java.lang.Object[] items)
Creates aJXComboBox
that contains the elements in the specified array.JXComboBox(java.util.Vector<?> items)
Creates aJXComboBox
that contains the elements in the specified Vector.JXComboBox(javax.swing.ComboBoxModel model)
Creates aJXComboBox
that takes its items from an existingComboBoxModel
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addHighlighter(Highlighter highlighter)
Adds a Highlighter.protected javax.swing.ListCellRenderer
createDefaultCellRenderer()
Creates and returns the default cell renderer to use.protected javax.swing.JComboBox.KeySelectionManager
createDefaultKeySelectionManager()
protected StringValueRegistry
createDefaultStringValueRegistry()
Creates and returns the default registry for StringValues.protected javax.swing.event.ChangeListener
createHighlighterChangeListener()
Creates and returns the ChangeListener observing Highlighters.protected ComponentAdapter
getComponentAdapter()
protected ComponentAdapter
getComponentAdapter(int index)
Convenience to access a configured ComponentAdapter.private CompoundHighlighter
getCompoundHighlighter()
Returns the CompoundHighlighter assigned to the table, null if none.private JXComboBox.DelegatingRenderer
getDelegatingRenderer()
protected javax.swing.event.ChangeListener
getHighlighterChangeListener()
Returns theChangeListener
to use with highlighters.Highlighter[]
getHighlighters()
Returns theHighlighter
s used by this column.protected static javax.swing.JList
getPopupListFor(javax.swing.JComboBox comboBox)
javax.swing.ListCellRenderer
getRenderer()
java.lang.String
getStringAt(int row)
Returns the string representation of the cell value at the given position.protected StringValueRegistry
getStringValueRegistry()
Returns the StringValueRegistry which defines the string representation for each cells.javax.swing.ListCellRenderer
getWrappedRenderer()
Returns the renderer installed by client code or the default if none has been set.private void
init()
private boolean
isStartingCellEdit(java.awt.event.KeyEvent e)
boolean
isUseHighlightersForCurrentValue()
PENDING JW to KS: review method naming - doesn't sound like valid English to me (no native speaker of course :-).protected boolean
processKeyBinding(javax.swing.KeyStroke ks, java.awt.event.KeyEvent e, int condition, boolean pressed)
void
removeHighlighter(Highlighter highlighter)
Removes the given Highlighter.private void
setCompoundHighlighter(CompoundHighlighter pipeline)
Assigns a CompoundHighlighter to the table, maybe null to remove all Highlighters.void
setHighlighters(Highlighter... highlighters)
Sets theHighlighter
s to the column, replacing any old settings.void
setRenderer(javax.swing.ListCellRenderer renderer)
void
setUseHighlightersForCurrentValue(boolean useHighlightersForCurrentValue)
void
updateUI()
-
Methods inherited from class javax.swing.JComboBox
actionPerformed, actionPropertyChanged, addActionListener, addItem, addItemListener, addPopupMenuListener, configureEditor, configurePropertiesFromAction, contentsChanged, createActionPropertyChangeListener, fireActionEvent, fireItemStateChanged, firePopupMenuCanceled, firePopupMenuWillBecomeInvisible, firePopupMenuWillBecomeVisible, getAccessibleContext, getAction, getActionCommand, getActionListeners, getEditor, getItemAt, getItemCount, getItemListeners, getKeySelectionManager, getMaximumRowCount, getModel, getPopupMenuListeners, getPrototypeDisplayValue, getSelectedIndex, getSelectedItem, getSelectedObjects, getUI, getUIClassID, hidePopup, insertItemAt, installAncestorListener, intervalAdded, intervalRemoved, isEditable, isLightWeightPopupEnabled, isPopupVisible, paramString, processKeyEvent, removeActionListener, removeAllItems, removeItem, removeItemAt, removeItemListener, removePopupMenuListener, selectedItemChanged, selectWithKeyChar, setAction, setActionCommand, setEditable, setEditor, setEnabled, setKeySelectionManager, setLightWeightPopupEnabled, setMaximumRowCount, setModel, setPopupVisible, setPrototypeDisplayValue, setSelectedIndex, setSelectedItem, setUI, showPopup
-
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, 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, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processMouseEvent, processMouseMotionEvent, 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, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
-
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
-
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, 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, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Field Detail
-
dataAdapter
private JXComboBox.ComboBoxAdapter dataAdapter
-
delegatingRenderer
private JXComboBox.DelegatingRenderer delegatingRenderer
-
stringValueRegistry
private StringValueRegistry stringValueRegistry
-
useHighlightersForCurrentValue
private boolean useHighlightersForCurrentValue
-
compoundHighlighter
private CompoundHighlighter compoundHighlighter
-
highlighterChangeListener
private javax.swing.event.ChangeListener highlighterChangeListener
-
pendingEvents
private java.util.List<java.awt.event.KeyEvent> pendingEvents
-
isDispatching
private boolean isDispatching
-
updatingUI
private boolean updatingUI
-
-
Constructor Detail
-
JXComboBox
public JXComboBox()
Creates aJXComboBox
with a default data model. The default data model is an empty list of objects. UseaddItem
to add items. By default the first item in the data model becomes selected.- See Also:
DefaultComboBoxModel
-
JXComboBox
public JXComboBox(javax.swing.ComboBoxModel model)
Creates aJXComboBox
that takes its items from an existingComboBoxModel
. Since theComboBoxModel
is provided, a combo box created using this constructor does not create a default combo box model and may impact how the insert, remove and add methods behave.- Parameters:
model
- theComboBoxModel
that provides the displayed list of items- See Also:
DefaultComboBoxModel
-
JXComboBox
public JXComboBox(java.lang.Object[] items)
Creates aJXComboBox
that contains the elements in the specified array. By default the first item in the array (and therefore the data model) becomes selected.- Parameters:
items
- an array of objects to insert into the combo box- See Also:
DefaultComboBoxModel
-
JXComboBox
public JXComboBox(java.util.Vector<?> items)
Creates aJXComboBox
that contains the elements in the specified Vector. By default the first item in the vector (and therefore the data model) becomes selected.- Parameters:
items
- an array of vectors to insert into the combo box- See Also:
DefaultComboBoxModel
-
-
Method Detail
-
init
private void init()
-
getPopupListFor
protected static javax.swing.JList getPopupListFor(javax.swing.JComboBox comboBox)
-
createDefaultKeySelectionManager
protected javax.swing.JComboBox.KeySelectionManager createDefaultKeySelectionManager()
This implementation uses the
StringValue
representation of the elements to determine the selected item.- Overrides:
createDefaultKeySelectionManager
in classjavax.swing.JComboBox
-
processKeyBinding
protected boolean processKeyBinding(javax.swing.KeyStroke ks, java.awt.event.KeyEvent e, int condition, boolean pressed)
- Overrides:
processKeyBinding
in classjavax.swing.JComboBox
-
isStartingCellEdit
private boolean isStartingCellEdit(java.awt.event.KeyEvent e)
-
getComponentAdapter
protected ComponentAdapter getComponentAdapter()
- Returns:
- the unconfigured ComponentAdapter.
-
getComponentAdapter
protected ComponentAdapter getComponentAdapter(int index)
Convenience to access a configured ComponentAdapter. Note: the column index of the configured adapter is always 0.- Parameters:
index
- the row index in view coordinates, must be valid.- Returns:
- the configured ComponentAdapter.
-
getStringValueRegistry
protected StringValueRegistry getStringValueRegistry()
Returns the StringValueRegistry which defines the string representation for each cells. This is strictly for internal use by the table, which has the responsibility to keep in synch with registered renderers.Currently exposed for testing reasons, client code is recommended to not use nor override.
- Returns:
- the current string value registry
-
createDefaultStringValueRegistry
protected StringValueRegistry createDefaultStringValueRegistry()
Creates and returns the default registry for StringValues.- Returns:
- the default registry for StringValues.
-
getStringAt
public java.lang.String getStringAt(int row)
Returns the string representation of the cell value at the given position.- Parameters:
row
- the row index of the cell in view coordinates- Returns:
- the string representation of the cell value as it will appear in the table.
-
getDelegatingRenderer
private JXComboBox.DelegatingRenderer getDelegatingRenderer()
-
createDefaultCellRenderer
protected javax.swing.ListCellRenderer createDefaultCellRenderer()
Creates and returns the default cell renderer to use. Subclasses may override to use a different type. Here: returns aDefaultListRenderer
.- Returns:
- the default cell renderer to use with this list.
-
getRenderer
public javax.swing.ListCellRenderer getRenderer()
Overridden to return the delegating renderer which is wrapped around the original to support highlighting. The returned renderer is of type DelegatingRenderer and guaranteed to not-null
- Overrides:
getRenderer
in classjavax.swing.JComboBox
- See Also:
setRenderer(ListCellRenderer)
,JXComboBox.DelegatingRenderer
-
getWrappedRenderer
public javax.swing.ListCellRenderer getWrappedRenderer()
Returns the renderer installed by client code or the default if none has been set.- Returns:
- the wrapped renderer.
- See Also:
setRenderer(ListCellRenderer)
-
setRenderer
public void setRenderer(javax.swing.ListCellRenderer renderer)
Overridden to wrap the given renderer in a DelegatingRenderer to support highlighting.
Note: the wrapping implies that the renderer returned from the getCellRenderer is not the renderer as given here, but the wrapper. To access the original, use
getWrappedCellRenderer
.- Overrides:
setRenderer
in classjavax.swing.JComboBox
- See Also:
getWrappedRenderer()
,getRenderer()
-
isUseHighlightersForCurrentValue
public boolean isUseHighlightersForCurrentValue()
PENDING JW to KS: review method naming - doesn't sound like valid English to me (no native speaker of course :-). Options are to change the property name to usingHighlightersForCurrentValue (as we did in JXMonthView after some debate) or stick to getXX. Thinking about it: maybe then the property should be usesHighlightersXX, that is third person singular instead of imperative, like in tracksVerticalViewport of JTable?- Returns:
true
if the combo box decorates the current value with highlighters;false
otherwise
-
setUseHighlightersForCurrentValue
public void setUseHighlightersForCurrentValue(boolean useHighlightersForCurrentValue)
-
getCompoundHighlighter
private CompoundHighlighter getCompoundHighlighter()
Returns the CompoundHighlighter assigned to the table, null if none. PENDING: open up for subclasses again?.- Returns:
- the CompoundHighlighter assigned to the table.
- See Also:
setCompoundHighlighter(CompoundHighlighter)
-
setCompoundHighlighter
private void setCompoundHighlighter(CompoundHighlighter pipeline)
Assigns a CompoundHighlighter to the table, maybe null to remove all Highlighters.The default value is
null
.PENDING: open up for subclasses again?.
- Parameters:
pipeline
- the CompoundHighlighter to use for renderer decoration.- See Also:
getCompoundHighlighter()
,addHighlighter(Highlighter)
,removeHighlighter(Highlighter)
-
setHighlighters
public void setHighlighters(Highlighter... highlighters)
Sets theHighlighter
s to the column, replacing any old settings. None of the given Highlighters must be null.- Parameters:
highlighters
- zero or more not null highlighters to use for renderer decoration.- See Also:
getHighlighters()
,addHighlighter(Highlighter)
,removeHighlighter(Highlighter)
-
getHighlighters
public Highlighter[] getHighlighters()
Returns theHighlighter
s used by this column. Maybe empty, but guarantees to be never null.- Returns:
- the Highlighters used by this column, guaranteed to never null.
- See Also:
setHighlighters(Highlighter[])
-
addHighlighter
public void addHighlighter(Highlighter highlighter)
Adds a Highlighter. Appends to the end of the list of used Highlighters.- Parameters:
highlighter
- theHighlighter
to add.- Throws:
java.lang.NullPointerException
- ifHighlighter
is null.- See Also:
removeHighlighter(Highlighter)
,setHighlighters(Highlighter[])
-
removeHighlighter
public void removeHighlighter(Highlighter highlighter)
Removes the given Highlighter.Does nothing if the Highlighter is not contained.
- Parameters:
highlighter
- the Highlighter to remove.- See Also:
addHighlighter(Highlighter)
,setHighlighters(Highlighter...)
-
getHighlighterChangeListener
protected javax.swing.event.ChangeListener getHighlighterChangeListener()
Returns theChangeListener
to use with highlighters. Lazily creates the listener.- Returns:
- the ChangeListener for observing changes of highlighters, guaranteed to be
not-null
-
createHighlighterChangeListener
protected javax.swing.event.ChangeListener createHighlighterChangeListener()
Creates and returns the ChangeListener observing Highlighters.A property change event is create for a state change.
- Returns:
- the ChangeListener defining the reaction to changes of highlighters.
-
updateUI
public void updateUI()
Overridden to update renderer and highlighters.
- Overrides:
updateUI
in classjavax.swing.JComboBox
-
-