Class AutoCompleteComboBoxEditor

  • All Implemented Interfaces:
    javax.swing.ComboBoxEditor

    public class AutoCompleteComboBoxEditor
    extends java.lang.Object
    implements javax.swing.ComboBoxEditor

    Wrapper around the combobox editor that translates combobox items into strings. The methods setItem and getItem are modified to account for the string conversion.

    This is necessary for those cases where the combobox items have no useful toString() method and a custom ObjectToStringConverter is used.

    If we do not do this, the interaction between ComboBoxEditor and JComboBox will result in firing ActionListener events with the string value of ComboBoxEditor as the currently selected value.

    • Field Detail

      • wrapped

        final javax.swing.ComboBoxEditor wrapped
        the original combo box editor
      • stringConverter

        final ObjectToStringConverter stringConverter
        the converter used to convert items into their string representation
      • oldItem

        private java.lang.Object oldItem
        last selected item
    • Constructor Detail

      • AutoCompleteComboBoxEditor

        public AutoCompleteComboBoxEditor​(javax.swing.ComboBoxEditor wrapped,
                                          ObjectToStringConverter stringConverter)
        Creates a new AutoCompleteComboBoxEditor.
        Parameters:
        wrapped - the original ComboBoxEditor to be wrapped
        stringConverter - the converter to use to convert items into their string representation.
    • Method Detail

      • getEditorComponent

        public java.awt.Component getEditorComponent()
        Specified by:
        getEditorComponent in interface javax.swing.ComboBoxEditor
      • setItem

        public void setItem​(java.lang.Object anObject)
        Specified by:
        setItem in interface javax.swing.ComboBoxEditor
      • getItem

        public java.lang.Object getItem()
        Specified by:
        getItem in interface javax.swing.ComboBoxEditor
      • selectAll

        public void selectAll()
        Specified by:
        selectAll in interface javax.swing.ComboBoxEditor
      • addActionListener

        public void addActionListener​(java.awt.event.ActionListener l)
        Specified by:
        addActionListener in interface javax.swing.ComboBoxEditor
      • removeActionListener

        public void removeActionListener​(java.awt.event.ActionListener l)
        Specified by:
        removeActionListener in interface javax.swing.ComboBoxEditor