Class JXComboBox

All Implemented Interfaces:
ActionListener, ImageObserver, ItemSelectable, MenuContainer, Serializable, EventListener, Accessible, ListDataListener

public class JXComboBox extends JComboBox
An enhanced JComboBox that provides the following additional functionality:

Auto-starts edits correctly for AutoCompletion when inside a JTable. A normal JComboBox fails to recognize the first key stroke when it has been decorated.

Adds highlighting support.

Author:
Karl Schaefer, Jeanette Winzenburg
See Also:
  • Constructor Details

    • JXComboBox

      public JXComboBox()
      Creates a JXComboBox with a default data model. The default data model is an empty list of objects. Use addItem to add items. By default the first item in the data model becomes selected.
      See Also:
    • JXComboBox

      public JXComboBox(ComboBoxModel model)
      Creates a JXComboBox that takes its items from an existing ComboBoxModel. Since the ComboBoxModel 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 - the ComboBoxModel that provides the displayed list of items
      See Also:
    • JXComboBox

      public JXComboBox(Object[] items)
      Creates a JXComboBox 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:
    • JXComboBox

      public JXComboBox(Vector<?> items)
      Creates a JXComboBox 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:
  • Method Details

    • getPopupListFor

      protected static JList getPopupListFor(JComboBox comboBox)
    • processKeyBinding

      protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed)
      Overrides:
      processKeyBinding in class JComboBox
    • 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.
    • createDefaultCellRenderer

      protected ListCellRenderer createDefaultCellRenderer()
      Creates and returns the default cell renderer to use. Subclasses may override to use a different type. Here: returns a DefaultListRenderer.
      Returns:
      the default cell renderer to use with this list.
    • getRenderer

      public 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 class JComboBox
      See Also:
    • getWrappedRenderer

      public ListCellRenderer getWrappedRenderer()
      Returns the renderer installed by client code or the default if none has been set.
      Returns:
      the wrapped renderer.
      See Also:
      • #setCellRenderer(TreeCellRenderer)
    • setRenderer

      public void setRenderer(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 class JComboBox
      See Also:
      • #getWrappedCellRenderer()
      • #getCellRenderer()
    • isUseHighlightersForCurrentValue

      public boolean isUseHighlightersForCurrentValue()
    • setUseHighlightersForCurrentValue

      public void setUseHighlightersForCurrentValue(boolean useHighlightersForCurrentValue)
    • setHighlighters

      public void setHighlighters(Highlighter... highlighters)
      Sets the Highlighters 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

      public Highlighter[] getHighlighters()
      Returns the Highlighters 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:
    • addHighlighter

      public void addHighlighter(Highlighter highlighter)
      Adds a Highlighter. Appends to the end of the list of used Highlighters.

      Parameters:
      highlighter - the Highlighter to add.
      Throws:
      NullPointerException - if Highlighter is null.
      See Also:
    • 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:
    • getHighlighterChangeListener

      protected ChangeListener getHighlighterChangeListener()
      Returns the ChangeListener to use with highlighters. Lazily creates the listener.
      Returns:
      the ChangeListener for observing changes of highlighters, guaranteed to be not-null
    • createHighlighterChangeListener

      protected 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 class JComboBox