简体   繁体   English

JavaFX:当用户单击 X 按钮时显示对话框窗口?

[英]JavaFX: Show a Dialog window when a user clicks the X button?

I have a basic JavaFX program and I'm trying to add functionality where if the user clicks the window's X button, a Dialog button appears.我有一个基本的 JavaFX 程序,我正在尝试添加功能,如果用户单击窗口的 X 按钮,则会出现一个对话框按钮。 How would I hook into the X button?我将如何连接到 X 按钮?

You can set an EventHandler to the stage's close request:您可以将EventHandler设置为舞台的关闭请求:

stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
    @Override
    public void handle(WindowEvent e) {
        // SHOW A DIALOG HERE
        Platform.exit();
        System.exit(0);
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当用户单击X按钮退出程序时,如何编写一个弹出对话框的编码? - How do I code a pop up dialog box to appear when the user clicks the X button to exit the program? 当用户单击后退按钮时,如何显示 Vaadin 23 的确认对话框? - How can I show a confirm dialog with Vaadin 23 when the user clicks on back button? 在swing GUI中,如何在用户单击按钮时将JPanel显示为最大化? - In swing GUI how to show a JPanel as maximized when the user clicks a button? Vaadin 14 Upload - 如何在用户单击选择文件对话框中的“取消”按钮时捕获事件 - Vaadin 14 Upload - how to catch event when user clicks Cancel button in choose file dialog JavaFX - 添加ScrollPane弹出窗口,当用户单击它时关闭该弹出窗口 - JavaFX - Adding a ScrollPane popup which closes when user clicks out of it 当用户单击JavaFX中Node绑定的外部时失去焦点 - Lose focus when user clicks outside Node's bound in JavaFX 用户单击主页按钮时终止活动 - Killing the activity when user clicks the home button JavaFX中带有计时器的计数按钮点击 - Count button clicks with timer in JavaFX JavaFX FXML对话框-无法使用X按钮关闭它 - JavaFX FXML Dialog - can't close it with the X button 用户单击通知时如何显示警报对话框? - How to bring alert dialog when user clicks on notification?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM