我已經嘗試了下面的代碼,它可以很好地處理鼠標事件,但是當我使用按鍵事件時,例如在沒有顯示結果的任何按鈕上輸入按鍵。在Javafx中輸入關鍵事件不能用於對話框?
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle(null);
alert.setHeaderText(null);
alert.setGraphic(null);
alert.setContentText("Choose your option.");
ButtonType buttonTypeOne = new ButtonType("One");
ButtonType buttonTypeTwo = new ButtonType("Two");
ButtonType buttonTypeThree = new ButtonType("Three");
alert.getButtonTypes().setAll(buttonTypeOne, buttonTypeTwo, buttonTypeThree);
Optional<ButtonType> result = alert.showAndWait();
if (result.get() == buttonTypeOne) {
System.out.println("One");
} else if (result.get() == buttonTypeTwo) {
System.out.println("Two");
} else if (result.get() == buttonTypeThree) {
System.out.println("Three");
}
它不起作用 –