@DefaultProperty(value="items") 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");
Modifier and Type | Class and Description |
---|---|
(package private) static class |
ChoiceBox.ChoiceBoxSelectionModel<T> |
Modifier and Type | Field and Description |
---|---|
private ObjectProperty<StringConverter<T>> |
converter |
private ObjectProperty<ObservableList<T>> |
items
The items to display in the choice box.
|
private ListChangeListener<T> |
itemsListener |
static EventType<Event> |
ON_HIDDEN
Called when the ChoiceBox popup has been hidden.
|
static EventType<Event> |
ON_HIDING
Called when the ChoiceBox popup will be hidden.
|
static EventType<Event> |
ON_SHOWING
Called prior to the ChoiceBox showing its popup after the user
has clicked or otherwise interacted with the ChoiceBox.
|
static EventType<Event> |
ON_SHOWN
Called after the ChoiceBox has shown its popup.
|
private ObjectProperty<EventHandler<ActionEvent>> |
onAction |
private ObjectProperty<EventHandler<Event>> |
onHidden |
private ObjectProperty<EventHandler<Event>> |
onHiding |
private ObjectProperty<EventHandler<Event>> |
onShowing |
private ObjectProperty<EventHandler<Event>> |
onShown |
private ChangeListener<T> |
selectedItemListener |
private ObjectProperty<SingleSelectionModel<T>> |
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 ObjectProperty<T> |
value |
USE_COMPUTED_SIZE, USE_PREF_SIZE
BASELINE_OFFSET_SAME_AS_HEIGHT
Constructor and Description |
---|
ChoiceBox()
Create a new ChoiceBox which has an empty list of items.
|
ChoiceBox(ObservableList<T> items)
Create a new ChoiceBox with the given set of items.
|
Modifier and Type | Method and Description |
---|---|
ObjectProperty<StringConverter<T>> |
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)
This method is called by the assistive technology to request the action
indicated by the argument should be executed.
|
StringConverter<T> |
getConverter() |
ObservableList<T> |
getItems() |
EventHandler<ActionEvent> |
getOnAction() |
EventHandler<Event> |
getOnHidden() |
EventHandler<Event> |
getOnHiding() |
EventHandler<Event> |
getOnShowing() |
EventHandler<Event> |
getOnShown() |
SingleSelectionModel<T> |
getSelectionModel() |
T |
getValue() |
void |
hide()
Closes the list of choices.
|
boolean |
isShowing() |
ObjectProperty<ObservableList<T>> |
itemsProperty() |
ObjectProperty<EventHandler<ActionEvent>> |
onActionProperty()
The ChoiceBox action, which is invoked whenever the ChoiceBox
value property is changed. |
ObjectProperty<EventHandler<Event>> |
onHiddenProperty()
Called just after the
ChoiceBox popup has been hidden. |
ObjectProperty<EventHandler<Event>> |
onHidingProperty()
Called just prior to the
ChoiceBox popup being hidden. |
ObjectProperty<EventHandler<Event>> |
onShowingProperty()
Called just prior to the
ChoiceBox popup being shown. |
ObjectProperty<EventHandler<Event>> |
onShownProperty()
Called just after the
ChoiceBox popup is shown. |
java.lang.Object |
queryAccessibleAttribute(AccessibleAttribute attribute,
java.lang.Object... parameters)
*
Accessibility handling *
*
|
ObjectProperty<SingleSelectionModel<T>> |
selectionModelProperty() |
void |
setConverter(StringConverter<T> value) |
void |
setItems(ObservableList<T> value) |
void |
setOnAction(EventHandler<ActionEvent> value) |
void |
setOnHidden(EventHandler<Event> value) |
void |
setOnHiding(EventHandler<Event> value) |
void |
setOnShowing(EventHandler<Event> value) |
void |
setOnShown(EventHandler<Event> value) |
void |
setSelectionModel(SingleSelectionModel<T> value) |
private void |
setShowing(boolean value) |
void |
setValue(T value) |
void |
show()
Opens the list of choices.
|
ReadOnlyBooleanProperty |
showingProperty() |
ObjectProperty<T> |
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, getSkin, getTooltip, impl_cssGetFocusTraversableInitialValue, impl_processCSS, isResizable, layoutChildren, loadSkinClass, setContextMenu, setSkin, setTooltip, skinClassNameProperty, skinProperty, tooltipProperty
backgroundProperty, borderProperty, cacheShapeProperty, centerShapeProperty, getBackground, getBorder, getHeight, getInsets, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getOpaqueInsets, getPadding, getPrefHeight, getPrefWidth, getShape, getUserAgentStylesheet, getWidth, heightProperty, impl_computeContains, impl_computeGeomBounds, impl_computeLayoutBounds, impl_createPeer, impl_notifyLayoutBoundsChanged, impl_pickNodeLocal, impl_updatePeer, insetsProperty, isCacheShape, isCenterShape, isScaleShape, isSnapToPixel, layoutInArea, layoutInArea, layoutInArea, layoutInArea, maxHeight, maxHeightProperty, maxWidth, maxWidthProperty, minHeight, minHeightProperty, minWidth, minWidthProperty, opaqueInsetsProperty, paddingProperty, positionInArea, positionInArea, prefHeight, prefHeightProperty, prefWidth, prefWidthProperty, resize, scaleShapeProperty, setBackground, setBorder, setCacheShape, setCenterShape, setHeight, setMaxHeight, setMaxSize, setMaxWidth, setMinHeight, setMinSize, setMinWidth, setOpaqueInsets, setPadding, setPrefHeight, setPrefSize, setPrefWidth, setScaleShape, setShape, setSnapToPixel, setWidth, shapeProperty, snappedBottomInset, snappedLeftInset, snappedRightInset, snappedTopInset, snapPosition, snapSize, snapSpace, snapToPixelProperty, widthProperty
getChildren, getChildrenUnmodifiable, getImpl_traversalEngine, getManagedChildren, getStylesheets, impl_getAllParentStylesheets, impl_processMXNode, impl_traversalEngineProperty, isNeedsLayout, layout, lookup, needsLayoutProperty, requestLayout, requestParentLayout, setImpl_traversalEngine, setNeedsLayout, updateBounds
accessibleHelpProperty, accessibleRoleDescriptionProperty, accessibleRoleProperty, accessibleTextProperty, addEventFilter, addEventHandler, applyCss, autosize, blendModeProperty, boundsInLocalProperty, boundsInParentProperty, buildEventDispatchChain, cacheHintProperty, cacheProperty, clipProperty, computeAreaInScreen, contains, contains, containsBounds, cursorProperty, depthTestProperty, disabledProperty, disableProperty, effectiveNodeOrientationProperty, effectProperty, eventDispatcherProperty, fireEvent, focusedProperty, focusTraversableProperty, getAccessibleHelp, getAccessibleRole, getAccessibleRoleDescription, getAccessibleText, getBlendMode, getBoundsInLocal, getBoundsInParent, getCacheHint, getClip, getContentBias, getCursor, getDepthTest, getEffect, getEffectiveNodeOrientation, getEventDispatcher, getId, getInputMethodRequests, getLayoutBounds, getLayoutX, getLayoutY, getLocalToParentTransform, getLocalToSceneTransform, getNodeOrientation, getOnContextMenuRequested, getOnDragDetected, getOnDragDone, getOnDragDropped, getOnDragEntered, getOnDragExited, getOnDragOver, getOnInputMethodTextChanged, getOnKeyPressed, getOnKeyReleased, getOnKeyTyped, getOnMouseClicked, getOnMouseDragEntered, getOnMouseDragExited, getOnMouseDragged, getOnMouseDragOver, getOnMouseDragReleased, getOnMouseEntered, getOnMouseExited, getOnMouseMoved, getOnMousePressed, getOnMouseReleased, getOnRotate, getOnRotationFinished, getOnRotationStarted, getOnScroll, getOnScrollFinished, getOnScrollStarted, getOnSwipeDown, getOnSwipeLeft, getOnSwipeRight, getOnSwipeUp, getOnTouchMoved, getOnTouchPressed, getOnTouchReleased, getOnTouchStationary, getOnZoom, getOnZoomFinished, getOnZoomStarted, getOpacity, getParent, getProperties, getPseudoClassStates, getRotate, getRotationAxis, getScaleX, getScaleY, getScaleZ, getScene, getStyle, getStyleableParent, getStyleClass, getTransforms, getTranslateX, getTranslateY, getTranslateZ, getTypeSelector, getUserData, hasProperties, hoverProperty, idProperty, impl_clearDirty, impl_computeIntersects, impl_cssGetCursorInitialValue, impl_findStyles, impl_geomChanged, impl_getLeafTransform, impl_getMatchingStyles, impl_getPeer, impl_getPivotX, impl_getPivotY, impl_getPivotZ, impl_getStyleMap, impl_hasTransforms, impl_intersects, impl_intersectsBounds, impl_isDirty, impl_isDirtyEmpty, impl_isShowMnemonics, impl_isTreeVisible, impl_layoutBoundsChanged, impl_markDirty, impl_pickNode, impl_processCSS, impl_reapplyCSS, impl_setShowMnemonics, impl_setStyleMap, impl_showMnemonicsProperty, impl_syncPeer, impl_transformsChanged, impl_traverse, impl_treeVisibleProperty, inputMethodRequestsProperty, intersects, intersects, isCache, isDisable, isDisabled, isFocused, isFocusTraversable, isHover, isManaged, isMouseTransparent, isPickOnBounds, isPressed, isVisible, layoutBoundsProperty, layoutXProperty, layoutYProperty, localToParent, localToParent, localToParent, localToParent, localToParent, localToParentTransformProperty, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToSceneTransformProperty, localToScreen, localToScreen, localToScreen, localToScreen, localToScreen, lookupAll, managedProperty, mouseTransparentProperty, nodeOrientationProperty, notifyAccessibleAttributeChanged, onContextMenuRequestedProperty, onDragDetectedProperty, onDragDoneProperty, onDragDroppedProperty, onDragEnteredProperty, onDragExitedProperty, onDragOverProperty, onInputMethodTextChangedProperty, onKeyPressedProperty, onKeyReleasedProperty, onKeyTypedProperty, onMouseClickedProperty, onMouseDragEnteredProperty, onMouseDragExitedProperty, onMouseDraggedProperty, onMouseDragOverProperty, onMouseDragReleasedProperty, onMouseEnteredProperty, onMouseExitedProperty, onMouseMovedProperty, onMousePressedProperty, onMouseReleasedProperty, onRotateProperty, onRotationFinishedProperty, onRotationStartedProperty, onScrollFinishedProperty, onScrollProperty, onScrollStartedProperty, onSwipeDownProperty, onSwipeLeftProperty, onSwipeRightProperty, onSwipeUpProperty, onTouchMovedProperty, onTouchPressedProperty, onTouchReleasedProperty, onTouchStationaryProperty, onZoomFinishedProperty, onZoomProperty, onZoomStartedProperty, opacityProperty, parentProperty, parentToLocal, parentToLocal, parentToLocal, parentToLocal, parentToLocal, pickOnBoundsProperty, pressedProperty, pseudoClassStateChanged, relocate, removeEventFilter, removeEventHandler, requestFocus, resizeRelocate, rotateProperty, rotationAxisProperty, scaleXProperty, scaleYProperty, scaleZProperty, sceneProperty, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, screenToLocal, screenToLocal, screenToLocal, setAccessibleHelp, setAccessibleRole, setAccessibleRoleDescription, setAccessibleText, setBlendMode, setCache, setCacheHint, setClip, setCursor, setDepthTest, setDisable, setDisabled, setEffect, setEventDispatcher, setEventHandler, setFocused, setFocusTraversable, setHover, setId, setInputMethodRequests, setLayoutX, setLayoutY, setManaged, setMouseTransparent, setNodeOrientation, setOnContextMenuRequested, setOnDragDetected, setOnDragDone, setOnDragDropped, setOnDragEntered, setOnDragExited, setOnDragOver, setOnInputMethodTextChanged, setOnKeyPressed, setOnKeyReleased, setOnKeyTyped, setOnMouseClicked, setOnMouseDragEntered, setOnMouseDragExited, setOnMouseDragged, setOnMouseDragOver, setOnMouseDragReleased, setOnMouseEntered, setOnMouseExited, setOnMouseMoved, setOnMousePressed, setOnMouseReleased, setOnRotate, setOnRotationFinished, setOnRotationStarted, setOnScroll, setOnScrollFinished, setOnScrollStarted, setOnSwipeDown, setOnSwipeLeft, setOnSwipeRight, setOnSwipeUp, setOnTouchMoved, setOnTouchPressed, setOnTouchReleased, setOnTouchStationary, setOnZoom, setOnZoomFinished, setOnZoomStarted, setOpacity, setPickOnBounds, setPressed, setRotate, setRotationAxis, setScaleX, setScaleY, setScaleZ, setStyle, setTranslateX, setTranslateY, setTranslateZ, setUserData, setVisible, snapshot, snapshot, startDragAndDrop, startFullDrag, styleProperty, toBack, toFront, toString, translateXProperty, translateYProperty, translateZProperty, usesMirroring, visibleProperty
public static final EventType<Event> ON_SHOWING
public static final EventType<Event> ON_SHOWN
public static final EventType<Event> ON_HIDING
public static final EventType<Event> ON_HIDDEN
private ObjectProperty<SingleSelectionModel<T>> selectionModel
private ChangeListener<T> selectedItemListener
private ReadOnlyBooleanWrapper showing
private ObjectProperty<ObservableList<T>> items
private final ListChangeListener<T> itemsListener
private ObjectProperty<StringConverter<T>> converter
private ObjectProperty<T> value
private ObjectProperty<EventHandler<ActionEvent>> onAction
private ObjectProperty<EventHandler<Event>> onShowing
private ObjectProperty<EventHandler<Event>> onShown
private ObjectProperty<EventHandler<Event>> onHiding
private ObjectProperty<EventHandler<Event>> onHidden
private static final PseudoClass SHOWING_PSEUDOCLASS_STATE
public ChoiceBox()
public ChoiceBox(ObservableList<T> items)
items
- public final void setSelectionModel(SingleSelectionModel<T> value)
public final SingleSelectionModel<T> getSelectionModel()
public final ObjectProperty<SingleSelectionModel<T>> selectionModelProperty()
public final boolean isShowing()
public final ReadOnlyBooleanProperty showingProperty()
private void setShowing(boolean value)
public final void setItems(ObservableList<T> value)
public final ObservableList<T> getItems()
public final ObjectProperty<ObservableList<T>> itemsProperty()
public ObjectProperty<StringConverter<T>> converterProperty()
javafx.util.converter
package can be set.public final void setConverter(StringConverter<T> value)
public final StringConverter<T> getConverter()
public ObjectProperty<T> valueProperty()
public final void setValue(T value)
public final T getValue()
public final ObjectProperty<EventHandler<ActionEvent>> 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.public final void setOnAction(EventHandler<ActionEvent> value)
public final EventHandler<ActionEvent> getOnAction()
public final ObjectProperty<EventHandler<Event>> onShowingProperty()
ChoiceBox
popup being shown.public final void setOnShowing(EventHandler<Event> value)
public final EventHandler<Event> getOnShowing()
public final ObjectProperty<EventHandler<Event>> onShownProperty()
ChoiceBox
popup is shown.public final void setOnShown(EventHandler<Event> value)
public final EventHandler<Event> getOnShown()
public final ObjectProperty<EventHandler<Event>> onHidingProperty()
ChoiceBox
popup being hidden.public final void setOnHiding(EventHandler<Event> value)
public final EventHandler<Event> getOnHiding()
public final ObjectProperty<EventHandler<Event>> onHiddenProperty()
ChoiceBox
popup has been hidden.public final void setOnHidden(EventHandler<Event> value)
public final EventHandler<Event> 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
attribute
- the requested attributeparameters
- optional list of parametersAccessibleAttribute
public void executeAccessibleAction(AccessibleAction action, java.lang.Object... parameters)
Node
This method is commonly overridden by subclasses to implement
action that are required for a specific role.
If a particular action is not handled, the super class implementation
must be called.
executeAccessibleAction
in class Control
action
- the action to executeparameters
- optional list of parametersAccessibleAction