Class ChoiceDialog<T>
java.lang.Object
javafx.scene.control.Dialog<T>
javafx.scene.control.ChoiceDialog<T>
- Type Parameters:
T- The type of the items to show to the user, and the type that is returned viaDialog.getResult()when the dialog is dismissed.
- All Implemented Interfaces:
EventTarget
A dialog that shows a list of choices to the user, from which they can pick
one item at most.

Example:
List<String> colors = List.of("Red", "Yellow", "Green");
ChoiceDialog choiceDialog = new ChoiceDialog<>("Yellow", colors);
choiceDialog.showAndWait();

- Since:
- JavaFX 8u40
- See Also:
-
Property Summary
PropertiesTypePropertyDescriptionfinal ReadOnlyObjectProperty<T> Returns the property representing the currently selected item in the dialog.Properties declared in class Dialog
contentText, dialogPane, graphic, headerText, height, onCloseRequest, onHidden, onHiding, onShowing, onShown, resizable, resultConverter, result, showing, title, width, x, yTypePropertyDescriptionfinal StringPropertyA property representing the content text for the dialog pane.final ObjectProperty<DialogPane> The root node of the dialog, theDialogPanecontains all visual elements shown in the dialog.final ObjectProperty<Node> The dialog graphic, presented either in the header, if one is showing, or to the left of thecontent.final StringPropertyA property representing the header text for the dialog pane.final ReadOnlyDoublePropertyProperty representing the height of the dialog.final ObjectProperty<EventHandler<DialogEvent>> Called when there is an external request to close thisDialog.final ObjectProperty<EventHandler<DialogEvent>> Called just after the Dialog has been hidden.final ObjectProperty<EventHandler<DialogEvent>> Called just prior to the Dialog being hidden.final ObjectProperty<EventHandler<DialogEvent>> Called just prior to the Dialog being shown.final ObjectProperty<EventHandler<DialogEvent>> Called just after the Dialog is shown.final BooleanPropertyRepresents whether the dialog is resizable.final ObjectProperty<Callback<ButtonType, T>> API to convert theButtonTypethat the user clicked on into a result that can be returned via theresultproperty.final ObjectProperty<T> A property representing what has been returned from the dialog.final ReadOnlyBooleanPropertyRepresents whether the dialog is currently showing.final StringPropertyReturn the titleProperty of the dialog.final ReadOnlyDoublePropertyProperty representing the width of the dialog.final ReadOnlyDoublePropertyThe horizontal location of thisDialog.final ReadOnlyDoublePropertyThe vertical location of thisDialog. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a default, empty instance of ChoiceDialog with no set items and a null default choice.ChoiceDialog(T defaultChoice, Collection<T> choices) Creates a new ChoiceDialog instance with the first argument specifying the default choice that should be shown to the user, and the second argument specifying a collection of all available choices for the user.ChoiceDialog(T defaultChoice, T... choices) Creates a new ChoiceDialog instance with the first argument specifying the default choice that should be shown to the user, and all following arguments considered a varargs array of all available choices for the user. -
Method Summary
Modifier and TypeMethodDescriptionfinal TReturns the default choice that was specified in the constructor.final ObservableList<T> getItems()Returns the list of all items that will be displayed to users.final TReturns the currently selected item in the dialog.final ReadOnlyObjectProperty<T> Returns the property representing the currently selected item in the dialog.final voidsetSelectedItem(T item) Sets the currently selected item in the dialog.Methods declared in class Dialog
addEventFilter, addEventHandler, buildEventDispatchChain, close, contentTextProperty, dialogPaneProperty, getContentText, getDialogPane, getGraphic, getHeaderText, getHeight, getModality, getOnCloseRequest, getOnHidden, getOnHiding, getOnShowing, getOnShown, getOwner, getResult, getResultConverter, getTitle, getWidth, getX, getY, graphicProperty, headerTextProperty, heightProperty, hide, initModality, initOwner, initStyle, isResizable, isShowing, onCloseRequestProperty, onHiddenProperty, onHidingProperty, onShowingProperty, onShownProperty, removeEventFilter, removeEventHandler, resizableProperty, resultConverterProperty, resultProperty, setContentText, setDialogPane, setGraphic, setHeaderText, setHeight, setOnCloseRequest, setOnHidden, setOnHiding, setOnShowing, setOnShown, setResizable, setResult, setResultConverter, setTitle, setWidth, setX, setY, show, showAndWait, showingProperty, titleProperty, widthProperty, xProperty, yPropertyModifier and TypeMethodDescriptionfinal <E extends Event>
voidaddEventFilter(EventType<E> eventType, EventHandler<? super E> eventFilter) Registers an event filter for this target.final <E extends Event>
voidaddEventHandler(EventType<E> eventType, EventHandler<? super E> eventHandler) Registers an event handler for this target.Construct an event dispatch chain for this target.final voidclose()Closes thisDialog.final StringPropertyA property representing the content text for the dialog pane.final ObjectProperty<DialogPane> The root node of the dialog, theDialogPanecontains all visual elements shown in the dialog.final StringReturns the currently-set content text for this DialogPane.final DialogPaneGets the value of thedialogPaneproperty.final NodeGets the value of thegraphicproperty.final StringReturns the currently-set header text for this DialogPane.final doubleReturns the height of the dialog.final ModalityRetrieves the modality attribute for this dialog.final EventHandler<DialogEvent> Gets the value of theonCloseRequestproperty.final EventHandler<DialogEvent> Gets the value of theonHiddenproperty.final EventHandler<DialogEvent> Gets the value of theonHidingproperty.final EventHandler<DialogEvent> Gets the value of theonShowingproperty.final EventHandler<DialogEvent> Gets the value of theonShownproperty.final WindowgetOwner()Retrieves the owner Window for this dialog, or null for an unowned dialog.final TGets the value of theresultproperty.final Callback<ButtonType, T> Gets the value of theresultConverterproperty.final StringgetTitle()Return the title of the dialog.final doublegetWidth()Returns the width of the dialog.final doublegetX()Gets the value of thexproperty.final doublegetY()Gets the value of theyproperty.final ObjectProperty<Node> The dialog graphic, presented either in the header, if one is showing, or to the left of thecontent.final StringPropertyA property representing the header text for the dialog pane.final ReadOnlyDoublePropertyProperty representing the height of the dialog.final voidhide()Hides thisDialog.final voidinitModality(Modality modality) Specifies the modality for this dialog.final voidSpecifies the ownerWindowfor this dialog, or null for a top-level, unowned dialog.final voidinitStyle(StageStyle style) Specifies the style for this dialog.final booleanReturns whether or not the dialog is resizable.final booleanReturns whether or not the dialog is showing.final ObjectProperty<EventHandler<DialogEvent>> Called when there is an external request to close thisDialog.final ObjectProperty<EventHandler<DialogEvent>> Called just after the Dialog has been hidden.final ObjectProperty<EventHandler<DialogEvent>> Called just prior to the Dialog being hidden.final ObjectProperty<EventHandler<DialogEvent>> Called just prior to the Dialog being shown.final ObjectProperty<EventHandler<DialogEvent>> Called just after the Dialog is shown.final <E extends Event>
voidremoveEventFilter(EventType<E> eventType, EventHandler<? super E> eventFilter) Unregisters a previously registered event filter from this target.final <E extends Event>
voidremoveEventHandler(EventType<E> eventType, EventHandler<? super E> eventHandler) Unregisters a previously registered event handler from this target.final BooleanPropertyRepresents whether the dialog is resizable.final ObjectProperty<Callback<ButtonType, T>> API to convert theButtonTypethat the user clicked on into a result that can be returned via theresultproperty.final ObjectProperty<T> A property representing what has been returned from the dialog.final voidsetContentText(String contentText) Sets the string to show in the dialog content area.final voidsetDialogPane(DialogPane value) Sets the value of thedialogPaneproperty.final voidsetGraphic(Node graphic) Sets the dialog graphic, which will be displayed either in the header, if one is showing, or to the left of thecontent.final voidsetHeaderText(String headerText) Sets the string to show in the dialog header area.final voidsetHeight(double height) Sets the height of the dialog.final voidsetOnCloseRequest(EventHandler<DialogEvent> value) Sets the value of theonCloseRequestproperty.final voidsetOnHidden(EventHandler<DialogEvent> value) Sets the value of theonHiddenproperty.final voidsetOnHiding(EventHandler<DialogEvent> value) Sets the value of theonHidingproperty.final voidsetOnShowing(EventHandler<DialogEvent> value) Sets the value of theonShowingproperty.final voidsetOnShown(EventHandler<DialogEvent> value) Sets the value of theonShownproperty.final voidsetResizable(boolean resizable) Sets whether the dialog can be resized by the user.final voidSets the value of theresultproperty.final voidsetResultConverter(Callback<ButtonType, T> value) Sets the value of theresultConverterproperty.final voidChange the Title of the dialog.final voidsetWidth(double width) Sets the width of the dialog.final voidsetX(double x) Sets the value of thexproperty.final voidsetY(double y) Sets the value of theyproperty.final voidshow()Shows the dialog but does not wait for a user response (in other words, this brings up a non-blocking dialog).Shows the dialog and waits for the user response (in other words, brings up a blocking dialog, with the returned value the users input).final ReadOnlyBooleanPropertyRepresents whether the dialog is currently showing.final StringPropertyReturn the titleProperty of the dialog.final ReadOnlyDoublePropertyProperty representing the width of the dialog.final ReadOnlyDoublePropertyThe horizontal location of thisDialog.final ReadOnlyDoublePropertyThe vertical location of thisDialog.
-
Property Details
-
selectedItem
Returns the property representing the currently selected item in the dialog.- See Also:
-
-
Constructor Details
-
ChoiceDialog
public ChoiceDialog()Creates a default, empty instance of ChoiceDialog with no set items and a null default choice. Users of this constructor will subsequently need to callgetItems()to specify which items to show to the user. -
ChoiceDialog
Creates a new ChoiceDialog instance with the first argument specifying the default choice that should be shown to the user, and all following arguments considered a varargs array of all available choices for the user. It is expected that the defaultChoice be one of the elements in the choices varargs array. If this is not true, then defaultChoice will be set to null and the dialog will show with the initial choice set to the first item in the list of choices.- Parameters:
defaultChoice- The item to display as the pre-selected choice in the dialog. This item must be contained within the choices varargs array.choices- All possible choices to present to the user.
-
ChoiceDialog
Creates a new ChoiceDialog instance with the first argument specifying the default choice that should be shown to the user, and the second argument specifying a collection of all available choices for the user. It is expected that the defaultChoice be one of the elements in the choices collection. If this is not true, then defaultChoice will be set to null and the dialog will show with the initial choice set to the first item in the list of choices.- Parameters:
defaultChoice- The item to display as the pre-selected choice in the dialog. This item must be contained within the choices varargs array.choices- All possible choices to present to the user.
-
-
Method Details
-
getSelectedItem
Returns the currently selected item in the dialog.- Returns:
- the currently selected item
-
selectedItemProperty
Returns the property representing the currently selected item in the dialog.- Returns:
- the currently selected item property
- See Also:
-
setSelectedItem
Sets the currently selected item in the dialog.- Parameters:
item- The item to select in the dialog.
-
getItems
Returns the list of all items that will be displayed to users. This list can be modified by the developer to add, remove, or reorder the items to present to the user.- Returns:
- the list of all items that will be displayed to users
-
getDefaultChoice
Returns the default choice that was specified in the constructor.- Returns:
- the default choice
-