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);