Top Description Fields Constructors Methods
org.controlsfx.control

public Class PrefixSelectionComboBox<T>

extends ComboBox<T>
Class Inheritance
Imports
impl.org.controlsfx.tools.PrefixSelectionCustomizer, javafx.beans.property.*, javafx.beans.value.ChangeListener, javafx.scene.control.ComboBox, java.util.Optional, java.util.function.BiFunction

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

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

See Also
PrefixSelectionCustomizer

Field Summary

Modifier and TypeField and Description
private final BooleanProperty
backSpaceAllowed

When allowed, the user can press on the back space to clear the current selection.

private final BooleanProperty
displayOnFocusedEnabled

When enabled, the ComboBox will display its popup upon focus gained.

private final ChangeListener<Boolean>
private final ObjectProperty<BiFunction<ComboBox<T>, String, Optional<T>>>
lookup

Allows setting a custom search criteria, based on the control and the typed selection.

private final IntegerProperty
typingDelay

Allows setting the delay until the current selection is reset, in ms.

Constructor Summary

AccessConstructor and Description
public
PrefixSelectionComboBox()

Create a non editable ComboBox with the "prefix selection" feature installed.

Method Summary

Modifier and TypeMethod and Description
public final BooleanProperty
public final BooleanProperty
public final BiFunction<ComboBox<T>, String, Optional<T>>
public final int
public final boolean
public final boolean
public final ObjectProperty<BiFunction<ComboBox<T>, String, Optional<T>>>
public final void
setBackSpaceAllowed(boolean value)

public final void
public final void
public final void
setTypingDelay(int value)

public final IntegerProperty
Inherited from javafx.scene.control.ComboBox:
buttonCellPropertycancelEditcellFactoryPropertycommitValueconverterPropertycreateDefaultSkineditorPropertygetButtonCellgetCellFactorygetConvertergetEditorgetItemsgetPlaceholdergetSelectionModelgetVisibleRowCountitemsPropertyplaceholderPropertyqueryAccessibleAttributeselectionModelPropertysetButtonCellsetCellFactorysetConvertersetItemssetPlaceholdersetSelectionModelsetVisibleRowCountvisibleRowCountProperty

Field Detail

backSpaceAllowedback to summary
private final BooleanProperty backSpaceAllowed

When allowed, the user can press on the back space to clear the current selection. Default is false

displayOnFocusedEnabledback to summary
private final BooleanProperty displayOnFocusedEnabled

When enabled, the ComboBox will display its popup upon focus gained. Default is false

focusedListenerback to summary
private final ChangeListener<Boolean> focusedListener
lookupback to summary
private final ObjectProperty<BiFunction<ComboBox<T>, String, Optional<T>>> lookup

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.

typingDelayback to summary
private final IntegerProperty typingDelay

Allows setting the delay until the current selection is reset, in ms. Default is 500 ms

Constructor Detail

PrefixSelectionComboBoxback to summary
public PrefixSelectionComboBox()

Create a non editable ComboBox with the "prefix selection" feature installed.

Method Detail

backSpaceAllowedPropertyback to summary
public final BooleanProperty backSpaceAllowedProperty()
displayOnFocusedEnabledPropertyback to summary
public final BooleanProperty displayOnFocusedEnabledProperty()
getLookupback to summary
public final BiFunction<ComboBox<T>, String, Optional<T>> getLookup()
getTypingDelayback to summary
public final int getTypingDelay()
isBackSpaceAllowedback to summary
public final boolean isBackSpaceAllowed()
isDisplayOnFocusedEnabledback to summary
public final boolean isDisplayOnFocusedEnabled()
lookupPropertyback to summary
public final ObjectProperty<BiFunction<ComboBox<T>, String, Optional<T>>> lookupProperty()
setBackSpaceAllowedback to summary
public final void setBackSpaceAllowed(boolean value)
setDisplayOnFocusedEnabledback to summary
public final void setDisplayOnFocusedEnabled(boolean value)
setLookupback to summary
public final void setLookup(BiFunction<ComboBox<T>, String, Optional<T>> value)
setTypingDelayback to summary
public final void setTypingDelay(int value)
typingDelayPropertyback to summary
public final IntegerProperty typingDelayProperty()