public class ChoiceBox<T> extends Control
By default, the ChoiceBox has no item selected unless otherwise specified. Although the ChoiceBox will only allow a user to select from the predefined list, it is possible for the developer to specify the selected item to be something other than what is available in the predefined list. This is required for several important use cases.
It means configuration of the ChoiceBox is order independent. You may either specify the items and then the selected item, or you may specify the selected item and then the items. Either way will function correctly.
ChoiceBox item selection is handled by
SelectionModel
As with ListView and ComboBox, it is possible to modify the
SelectionModel
that is used,
although this is likely to be rarely changed. ChoiceBox supports only a
single selection model, hence the default used is a SingleSelectionModel
.
import javafx.scene.control.ChoiceBox; ChoiceBox cb = new ChoiceBox(); cb.getItems().addAll("item1", "item2", "item3");
Type | Property and Description |
---|---|
<any> |
converter
Allows a way to specify how to represent objects in the items list.
|
<any> |
items
The items to display in the choice box.
|
<any> |
onAction
The ChoiceBox action, which is invoked whenever the ChoiceBox
value property is changed. |
<any> |
onHidden
Called just after the
ChoiceBox popup has been hidden. |
<any> |
onHiding
Called just prior to the
ChoiceBox popup being hidden. |
<any> |
onShowing
Called just prior to the
ChoiceBox popup being shown. |
<any> |
onShown
Called just after the
ChoiceBox popup is shown. |
<any> |
selectionModel
The selection model for the ChoiceBox.
|
ReadOnlyBooleanProperty |
showing
Indicates whether the drop down is displaying the list of choices to the
user.
|
<any> |
value
The value of this ChoiceBox is defined as the selected item in the ChoiceBox
selection model.
|
contextMenuProperty, skinClassNameProperty, skinProperty, tooltipProperty
Modifier and Type | Class and Description |
---|---|
(package private) static class |
ChoiceBox.ChoiceBoxSelectionModel<T> |
Modifier and Type | Field and Description |
---|---|
private <any> |
converter |
private <any> |
items
The items to display in the choice box.
|
private <any> |
itemsListener |
static <any> |
ON_HIDDEN
Called when the ChoiceBox popup has been hidden.
|
static <any> |
ON_HIDING
Called when the ChoiceBox popup will be hidden.
|
static <any> |
ON_SHOWING
Called prior to the ChoiceBox showing its popup after the user
has clicked or otherwise interacted with the ChoiceBox.
|
static <any> |
ON_SHOWN
Called after the ChoiceBox has shown its popup.
|
private <any> |
onAction |
private <any> |
onHidden |
private <any> |
onHiding |
private <any> |
onShowing |
private <any> |
onShown |
private <any> |
selectedItemListener |
private <any> |
selectionModel
The selection model for the ChoiceBox.
|
private ReadOnlyBooleanWrapper |
showing
Indicates whether the drop down is displaying the list of choices to the
user.
|
private static PseudoClass |
SHOWING_PSEUDOCLASS_STATE
*
Stylesheet Handling *
*
|
private <any> |
value |
Constructor and Description |
---|
ChoiceBox()
Create a new ChoiceBox which has an empty list of items.
|
ChoiceBox(<any> items)
Create a new ChoiceBox with the given set of items.
|
Modifier and Type | Method and Description |
---|---|
<any> |
converterProperty()
Allows a way to specify how to represent objects in the items list.
|
protected Skin<?> |
createDefaultSkin()
Create a new instance of the default skin for this control.
|
void |
executeAccessibleAction(AccessibleAction action,
java.lang.Object... parameters) |
<any> |
getConverter()
Gets the value of the property converter.
|
<any> |
getItems()
Gets the value of the property items.
|
<any> |
getOnAction()
Gets the value of the property onAction.
|
<any> |
getOnHidden()
Gets the value of the property onHidden.
|
<any> |
getOnHiding()
Gets the value of the property onHiding.
|
<any> |
getOnShowing()
Gets the value of the property onShowing.
|
<any> |
getOnShown()
Gets the value of the property onShown.
|
SingleSelectionModel<T> |
getSelectionModel()
Gets the value of the property selectionModel.
|
T |
getValue()
Gets the value of the property value.
|
void |
hide()
Closes the list of choices.
|
boolean |
isShowing()
Gets the value of the property showing.
|
<any> |
itemsProperty()
The items to display in the choice box.
|
<any> |
onActionProperty()
The ChoiceBox action, which is invoked whenever the ChoiceBox
value property is changed. |
<any> |
onHiddenProperty()
Called just after the
ChoiceBox popup has been hidden. |
<any> |
onHidingProperty()
Called just prior to the
ChoiceBox popup being hidden. |
<any> |
onShowingProperty()
Called just prior to the
ChoiceBox popup being shown. |
<any> |
onShownProperty()
Called just after the
ChoiceBox popup is shown. |
java.lang.Object |
queryAccessibleAttribute(AccessibleAttribute attribute,
java.lang.Object... parameters) |
<any> |
selectionModelProperty()
The selection model for the ChoiceBox.
|
void |
setConverter(<any> value)
Sets the value of the property converter.
|
void |
setItems(<any> value)
Sets the value of the property items.
|
void |
setOnAction(<any> value)
Sets the value of the property onAction.
|
void |
setOnHidden(<any> value)
Sets the value of the property onHidden.
|
void |
setOnHiding(<any> value)
Sets the value of the property onHiding.
|
void |
setOnShowing(<any> value)
Sets the value of the property onShowing.
|
void |
setOnShown(<any> value)
Sets the value of the property onShown.
|
void |
setSelectionModel(SingleSelectionModel<T> value)
Sets the value of the property selectionModel.
|
private void |
setShowing(boolean value) |
void |
setValue(T value)
Sets the value of the property value.
|
void |
show()
Opens the list of choices.
|
ReadOnlyBooleanProperty |
showingProperty()
Indicates whether the drop down is displaying the list of choices to the
user.
|
<any> |
valueProperty()
The value of this ChoiceBox is defined as the selected item in the ChoiceBox
selection model.
|
computeMaxHeight, computeMaxWidth, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, contextMenuProperty, getBaselineOffset, getClassCssMetaData, getContextMenu, getControlChildren, getControlCssMetaData, getCssMetaData, getInitialFocusTraversable, getSkin, getTooltip, isResizable, layoutChildren, loadSkinClass, setContextMenu, setSkin, setTooltip, skinClassNameProperty, skinProperty, tooltipProperty
public final <any> selectionModelProperty
public final ReadOnlyBooleanProperty showingProperty
isShowing()
public final <any> itemsProperty
getItems()
,
#setItems()
public <any> converterProperty
javafx.util.converter
package can be set.getConverter()
,
#setConverter()
public <any> valueProperty
getValue()
,
setValue(T)
public final <any> onActionProperty
value
property is changed. This
may be due to the value property being programmatically changed or when the
user selects an item in a popup menu.getOnAction()
,
#setOnAction()
public final <any> onShowingProperty
ChoiceBox
popup being shown.getOnShowing()
,
#setOnShowing()
public final <any> onShownProperty
ChoiceBox
popup is shown.getOnShown()
,
#setOnShown()
public final <any> onHidingProperty
ChoiceBox
popup being hidden.getOnHiding()
,
#setOnHiding()
public final <any> onHiddenProperty
ChoiceBox
popup has been hidden.getOnHidden()
,
#setOnHidden()
public static final <any> ON_SHOWING
public static final <any> ON_SHOWN
public static final <any> ON_HIDING
public static final <any> ON_HIDDEN
private <any> selectionModel
private <any> selectedItemListener
private ReadOnlyBooleanWrapper showing
private <any> items
private final <any> itemsListener
private <any> converter
private <any> value
private <any> onAction
private <any> onShowing
private <any> onShown
private <any> onHiding
private <any> onHidden
private static final PseudoClass SHOWING_PSEUDOCLASS_STATE
public ChoiceBox()
public ChoiceBox(<any> items)
items
- the set of itemspublic final void setSelectionModel(SingleSelectionModel<T> value)
public final SingleSelectionModel<T> getSelectionModel()
public final <any> selectionModelProperty()
public final boolean isShowing()
public final ReadOnlyBooleanProperty showingProperty()
isShowing()
private void setShowing(boolean value)
public final void setItems(<any> value)
public final <any> getItems()
public final <any> itemsProperty()
getItems()
,
#setItems()
public <any> converterProperty()
javafx.util.converter
package can be set.getConverter()
,
#setConverter()
public final void setConverter(<any> value)
public final <any> getConverter()
public <any> valueProperty()
getValue()
,
setValue(T)
public final void setValue(T value)
public final T getValue()
public final <any> onActionProperty()
value
property is changed. This
may be due to the value property being programmatically changed or when the
user selects an item in a popup menu.getOnAction()
,
#setOnAction()
public final void setOnAction(<any> value)
public final <any> getOnAction()
public final <any> onShowingProperty()
ChoiceBox
popup being shown.getOnShowing()
,
#setOnShowing()
public final void setOnShowing(<any> value)
public final <any> getOnShowing()
public final <any> onShownProperty()
ChoiceBox
popup is shown.getOnShown()
,
#setOnShown()
public final void setOnShown(<any> value)
public final <any> getOnShown()
public final <any> onHidingProperty()
ChoiceBox
popup being hidden.getOnHiding()
,
#setOnHiding()
public final void setOnHiding(<any> value)
public final <any> getOnHiding()
public final <any> onHiddenProperty()
ChoiceBox
popup has been hidden.getOnHidden()
,
#setOnHidden()
public final void setOnHidden(<any> value)
public final <any> getOnHidden()
public void show()
public void hide()
protected Skin<?> createDefaultSkin()
-fx-skin
or set explicitly in a sub-class with setSkin(...)
.createDefaultSkin
in class Control
public java.lang.Object queryAccessibleAttribute(AccessibleAttribute attribute, java.lang.Object... parameters)
queryAccessibleAttribute
in class Control
public void executeAccessibleAction(AccessibleAction action, java.lang.Object... parameters)
executeAccessibleAction
in class Control