Class PrefixSelectionComboBox<T>

  • All Implemented Interfaces:
    Styleable, EventTarget, Skinnable

    public class PrefixSelectionComboBox<T>
    extends ComboBox<T>
    A simple extension of the ComboBox which selects an entry of its item list based on keyboard input. The user can type letters or digits on the keyboard and the control will attempt to select the first item it can find with a matching prefix. This will only be enabled, when the ComboBox is not editable, so this class will be setup as non editable by default.

    This feature is available natively on the Windows combo box control, so many users have asked for it. There is a feature request to include this feature into JavaFX (Issue RT-18064). The class is published as part of ControlsFX to allow testing and feedback.

    Example

    Let's look at an example to clarify this. The combo box offers the items ["Aaaaa", "Abbbb", "Abccc", "Abcdd", "Abcde"]. The user now types "abc" in quick succession (and then stops typing). The combo box will select a new entry on every key pressed. The first entry it will select is "Aaaaa" since it is the first entry that starts with an "a" (case ignored). It will then select "Abbbb", since this is the first entry that started with "ab" and will finally settle for "Abccc".

      Keys typedElement selected
      aAaaaa
      aaaAaaaa
      abAbbbb
      abcAbccc
      xyz-

    If you want to modify an existing ComboBox you can use the PrefixSelectionCustomizer directly to do this.

    See Also:
    PrefixSelectionCustomizer
    • Constructor Detail

      • PrefixSelectionComboBox

        public PrefixSelectionComboBox()
        Create a non editable ComboBox with the "prefix selection" feature installed.
    • Method Detail

      • isDisplayOnFocusedEnabled

        public final boolean isDisplayOnFocusedEnabled()
        Gets the value of the property displayOnFocusedEnabled.
        Property description:
        When enabled, the ComboBox will display its popup upon focus gained. Default is false
      • setDisplayOnFocusedEnabled

        public final void setDisplayOnFocusedEnabled​(boolean value)
        Sets the value of the property displayOnFocusedEnabled.
        Property description:
        When enabled, the ComboBox will display its popup upon focus gained. Default is false
      • isBackSpaceAllowed

        public final boolean isBackSpaceAllowed()
        Gets the value of the property backSpaceAllowed.
        Property description:
        When allowed, the user can press on the back space to clear the current selection. Default is false
      • setBackSpaceAllowed

        public final void setBackSpaceAllowed​(boolean value)
        Sets the value of the property backSpaceAllowed.
        Property description:
        When allowed, the user can press on the back space to clear the current selection. Default is false
      • getTypingDelay

        public final int getTypingDelay()
        Gets the value of the property typingDelay.
        Property description:
        Allows setting the delay until the current selection is reset, in ms. Default is 500 ms
      • setTypingDelay

        public final void setTypingDelay​(int value)
        Sets the value of the property typingDelay.
        Property description:
        Allows setting the delay until the current selection is reset, in ms. Default is 500 ms
      • getLookup

        public final BiFunction<ComboBox,​String,​Optional> getLookup()
        Gets the value of the property lookup.
        Property description:
        Allows setting a custom search criteria, based on the control and the typed selection. The default criteria searchs for the first matching item that starts with the typed selection, being case insenstitive.
      • setLookup

        public final void setLookup​(BiFunction<ComboBox,​String,​Optional> value)
        Sets the value of the property lookup.
        Property description:
        Allows setting a custom search criteria, based on the control and the typed selection. The default criteria searchs for the first matching item that starts with the typed selection, being case insenstitive.