- 所有已实现的接口:
javafx.scene.control.Skin<javafx.scene.control.ComboBox<T>>
The user can type multiple words. The popup list is filtered checking if the string representation of an item contains all filter words (ignoring case).
After filtering the list, the user can select an entry by
- Pressing ENTER: the selected item is applied, the popup closes. If no item is selected, the first item is applied. To select another item the cursor keys can be used before pressing ENTER.
- Pressing TAB: Same as ENTER, but in addition the focus is transferred to the next control.
- Selecting an item using the mouse closes the popup.
When pressing ESCAPE while the popup is showing, the item that was selected when the popup opened will be re-selected (even if the user did select another item using the cursor keys.
Other than the ComboBox, the SearchableComboBox does open the Popup when using
the cursor keys (the ComboBox does only change the selected item without
opening the popup). This combined with the behavior of the ESCAPE key does allow to
go through the list of items with the cursor keys and than press ESCAPE to revert
the changes.
Example
Let's look at an example to clarify this. The combo box offers the items ["Berlin", "Bern", "Munich", "Paris", "New York", "Alberta"]. The user now types "ber" into the search field. The combo box popup will only show ["Berlin", "Bern", "Alberta"].
To select the first item ("Berlin"), the user can now either just press ENTER or TAB, or first select this item using the cursor DOWN key and press ENTER or TAB afterwards, or select this item using the mouse.
To select the second or third item, the user either must use the cursor keys first, use the mouse, or type more text until the searched item is the first (or only) item in the list.
If you want to modify an existing ComboBox you can set the skin to
SearchableComboBoxSkin (e.g. using Control.setSkin(Skin) or in CSS.
- 另请参阅:
-
字段概要
字段修饰符和类型字段说明private final javafx.scene.control.ComboBox<T> A "normal" combobox used internally as a delegate to get the default combo box behavior.private static final javafx.scene.image.Imageprivate TUsed when pressing ESCprivate final CustomTextFieldThe search field shown when the popup is shown. -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明private voidprivate voidcheckApplyAndCancel(javafx.scene.input.KeyEvent e) Used to alter the behaviour.private voidcheckOpenPopup(javafx.scene.input.KeyEvent e) Show the popup on UP, DOWN, and on beginning typing a word.private javafx.scene.control.ComboBox<T> private javafx.collections.transformation.FilteredList<T> private CustomTextFieldprivate StringgetDisplayText(T value) Create a text for the given item, that can be used to compare with the filter text.protected voidlayoutChildren(double x, double y, double w, double h) Return the Predicate to filter the popup items based on the search field.Return the Predicate to filter the popup items based on the given search text.private voidThe default behavior of the ComboBoxListViewSkin is to close the popup on ENTER and SPACE, but we need to override this behavior.private voidCalled every time the filter text changes.从类继承的方法 javafx.scene.control.SkinBase
computeBaselineOffset, computeMaxHeight, computeMaxWidth, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, consumeMouseEvents, dispose, executeAccessibleAction, getChildren, getClassCssMetaData, getCssMetaData, getNode, getSkinnable, layoutInArea, layoutInArea, layoutInArea, positionInArea, positionInArea, pseudoClassStateChanged, queryAccessibleAttribute, registerChangeListener, registerInvalidationListener, registerListChangeListener, snappedBottomInset, snappedLeftInset, snappedRightInset, snappedTopInset, snapPosition, snapPositionX, snapPositionY, snapSize, snapSizeX, snapSizeY, snapSpace, snapSpaceX, snapSpaceY, unregisterChangeListeners, unregisterInvalidationListeners, unregisterListChangeListeners从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait从接口继承的方法 javafx.scene.control.Skin
install
-
字段详细资料
-
filterIcon
private static final javafx.scene.image.Image filterIcon -
filteredComboBox
A "normal" combobox used internally as a delegate to get the default combo box behavior. This combo box contains the filtered items and handles the popup. -
searchField
The search field shown when the popup is shown. -
previousValue
Used when pressing ESC
-
-
构造器详细资料
-
SearchableComboBoxSkin
-
-
方法详细资料
-
layoutChildren
protected void layoutChildren(double x, double y, double w, double h) - 覆盖:
layoutChildren在类中javafx.scene.control.SkinBase<javafx.scene.control.ComboBox<T>>
-
createSearchField
-
createFilteredComboBox
-
bindSearchFieldAndFilteredComboBox
private void bindSearchFieldAndFilteredComboBox() -
createFilteredList
-
updateFilter
private void updateFilter()Called every time the filter text changes. -
predicate
Return the Predicate to filter the popup items based on the search field. -
predicate
Return the Predicate to filter the popup items based on the given search text. -
getDisplayText
Create a text for the given item, that can be used to compare with the filter text. -
preventDefaultComboBoxKeyListener
private void preventDefaultComboBoxKeyListener()The default behavior of the ComboBoxListViewSkin is to close the popup on ENTER and SPACE, but we need to override this behavior. -
checkApplyAndCancel
private void checkApplyAndCancel(javafx.scene.input.KeyEvent e) Used to alter the behaviour. React on Enter, Tab and ESC. -
checkOpenPopup
private void checkOpenPopup(javafx.scene.input.KeyEvent e) Show the popup on UP, DOWN, and on beginning typing a word.
-