你不应该专注于X,而是关注常见的关闭请求,如下所示:
primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent event) {
// consume event
event.consume();
// show close dialog
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle("Close Confirmation");
alert.setHeaderText("Do you really want to quit?");
alert.initOwner( primaryStage);
Optional<ButtonType> result = alert.showAndWait();
if (result.get() == ButtonType.OK){
Platform.exit();
}
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4606 次 |
| 最近记录: |