Class PrefixSelectionChoiceBox<T>

  • All Implemented Interfaces:
    Styleable, EventTarget, Skinnable

    public class PrefixSelectionChoiceBox<T>
    extends ChoiceBox<T>

    A simple extension of the ChoiceBox which selects an entry of its item list based on keyboard input. The user can type letters or digits on the keyboard and die ChoiceBox will attempt to select the first item it can find with a matching prefix.

    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 ContorlsFX to allow testing and feedback.


    Let's look at an example to clarify this. The choice box offers the items ["Aaaaa", "Abbbb", "Abccc", "Abcdd", "Abcde"]. The user now types "abc" in quick succession (and then stops typing). The choice 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

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

    See Also:
    • Constructor Detail

      • PrefixSelectionChoiceBox

        public PrefixSelectionChoiceBox()
        Create a non editable ChoiceBox with the "prefix selection" feature installed.