您不应该关注X,而应该关注像这样的通用关闭请求:
primaryStage.setonCloseRequest(new EventHandler<WindowEvent>() { @Override public void handle(WindowEvent event) { // consume event event.consume(); // show close dialog alert alert = new alert(alertType./confirm/iATION); alert.setTitle("Close /confirm/iation"); alert.setHeaderText("Do you really want to quit?"); alert.initOwner( primaryStage); Optional<ButtonType> result = alert.showAndWait(); if (result.get() == ButtonType.OK){ Platform.exit(); } }});


