ChoiceDialog
ChoiceDialog
允許使用者從選項列表中選擇一個專案。
List<String> options = new ArrayList<>();
options.add("42");
options.add("9");
options.add("467829");
options.add("Other");
ChoiceDialog<String> dialog = new ChoiceDialog<>(options.get(0), options);
dialog.setHeaderText("Choose your favourite number.");
dialog.setTitle("Favourite number?");
dialog.setContentText("Your favourite number:");
Optional<String> choice = dialog.showAndWait();
String s = choice.map(c -> "Other".equals(c) ?
"Unfortunately your favourite number is not available!"
: "Nice! I like " + c + " too!")
.orElse("You really don't want to tell me, huh?");
System.out.println(s);