Class AutoCompComboBoxModel<E>

    • Field Detail

      • comparator

        private Comparator<E> comparator
        The comparator used by findBestCandidate(java.lang.String)

        The comparator is used exclusively for autocompleting, and not for sorting the combobox entries. The default comparator sorts elements in alphabetical order according to E::toString.

    • Method Detail

      • setComparator

        public void setComparator​(Comparator<E> comparator)
        Sets a custom comparator.

        Example: setComparator(Comparator.comparing(E::getPriority).thenComparing(E::toString));

        If <E> implements Comparable you can automagically create a comparator with setComparator(Comparator.naturalOrder());.

        Parameters:
        comparator - A custom comparator.
      • findBestCandidate

        public E findBestCandidate​(String prefix)
        Finds the best candidate for autocompletion.

        Looks in the model for an element whose prefix matches prefix. If more than one element matches prefix, returns the first of the matching elements (first according to comparator). An element that is equal to prefix is always preferred.

        Parameters:
        prefix - The prefix to match.
        Returns:
        The best candidate (may be null)