自定義按鈕文字
通過自己建立 ButtonType
例項,可以自定義按鈕中顯示的文字:
ButtonType answer = new ButtonType("42");
ButtonType somethingElse = new ButtonType("54");
Alert alert = new Alert(Alert.AlertType.NONE, "What do you get when you multiply six by nine?", answer, somethingElse);
ButtonType result = alert.showAndWait().orElse(somethingElse);
Alert resultDialog = new Alert(Alert.AlertType.INFORMATION,
answer.equals(result) ? "Correct" : "wrong",
ButtonType.OK);
resultDialog.show();