Top Description Fields Constructors Methods
impl.org.controlsfx.tools

public Class PrefixSelectionCustomizer

extends Object
Class Inheritance
Imports
javafx.event.EventHandler, javafx.scene.control.ChoiceBox, .ComboBox, .Control, .ListView, javafx.scene.control.skin.ComboBoxListViewSkin, javafx.scene.input.KeyCode, .KeyEvent, org.controlsfx.control.PrefixSelectionChoiceBox, .PrefixSelectionComboBox, java.util.Locale, .Objects, .Optional, java.util.concurrent.Executors, .ScheduledExecutorService, .ScheduledFuture, .TimeUnit, java.util.function.BiFunction

This utility class can be used to customize a ChoiceBox or ComboBox and enable the "prefix selection" feature. This will enable the user to type letters or digits on the keyboard while the ChoiceBox or ComboBox has the focus. By default, the ChoiceBox or ComboBox will attempt to select the first item it can find with a matching prefix ignoring case.

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.

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".

Usage

A common use case is to customize a ChoiceBox or ComboBox that has been loaded as part of an FXML. In this case you can use the utility methods customize(ChoiceBox) or customize(ComboBox). This will install a EventHandler that monitors the KeyEvent events.

If you are coding, you can also use the preconfigured classes PrefixSelectionChoiceBox and PrefixSelectionComboBox as a substitute for ChoiceBox and ComboBox. In this case, PrefixSelectionComboBox includes some properties that will allow modifying the elapsed time before the selection is clear, listen to back space to clear the selection, show the popup when the control gains the focus, or set a different lookup criteria.

See Also
PrefixSelectionChoiceBox, PrefixSelectionComboBox

Field Summary

Modifier and TypeField and Description
public static final BiFunction<ChoiceBox<T>, String, Optional<T>>
public static final BiFunction<ComboBox<T>, String, Optional<T>>
public static final int
private static EventHandler<KeyEvent>
private static final String
private static final Object

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static void
customize(ComboBox<?>
The ComboBox that should be customized
comboBox
)

This will install an EventHandler that monitors the KeyEvent events to enable the "prefix selection" feature.

public static void
customize(ChoiceBox<?>
The ChoiceBox that should be customized
choiceBox
)

This will install an EventHandler that monitors the KeyEvent events to enable the "prefix selection" feature.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_LOOKUP_CHOICEBOXback to summary
public static final BiFunction<ChoiceBox<T>, String, Optional<T>> DEFAULT_LOOKUP_CHOICEBOX
DEFAULT_LOOKUP_COMBOBOXback to summary
public static final BiFunction<ComboBox<T>, String, Optional<T>> DEFAULT_LOOKUP_COMBOBOX
DEFAULT_TYPING_DELAYback to summary
public static final int DEFAULT_TYPING_DELAY
handlerback to summary
private static EventHandler<KeyEvent> handler
SELECTION_PREFIX_STRINGback to summary
private static final String SELECTION_PREFIX_STRING
SELECTION_PREFIX_TASKback to summary
private static final Object SELECTION_PREFIX_TASK

Constructor Detail

PrefixSelectionCustomizerback to summary
public PrefixSelectionCustomizer()

Method Detail

customizeback to summary
public static void customize(ComboBox<?> comboBox)

This will install an EventHandler that monitors the KeyEvent events to enable the "prefix selection" feature. The EventHandler will only be installed if the ComboBox is not editable.

Parameters
comboBox:ComboBox<?>

The ComboBox that should be customized

See Also
PrefixSelectionCustomizer
customizeback to summary
public static void customize(ChoiceBox<?> choiceBox)

This will install an EventHandler that monitors the KeyEvent events to enable the "prefix selection" feature.

Parameters
choiceBox:ChoiceBox<?>

The ChoiceBox that should be customized

See Also
PrefixSelectionCustomizer