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 typed | Element selected | |
|---|---|---|
| a | Aaaaa | |
| aaa | Aaaaa | |
| ab | Abbbb | |
| abc | Abccc | |
| xyz | - |
If you want to modify an existing ChoiceBox you can use the
PrefixSelectionCustomizer directly to do this.
PrefixSelectionCustomizer
| Access | Constructor and Description |
|---|---|
| public | PrefixSelectionChoiceBox()
Create a non editable |
| PrefixSelectionChoiceBox | back to summary |
|---|---|
| public PrefixSelectionChoiceBox() Create a non editable | |