How do I get the close event of a stage in JavaFX?

后端 未结 3 1489
有刺的猬
有刺的猬 2021-02-19 03:09

In JavaFX, how can I get the event if a user clicks the Close Button(X) (right most top cross) a stage?

I want my application to print a debug message when the window is

3条回答
  •  攒了一身酷
    2021-02-19 04:11

    stage.setOnCloseRequest(new EventHandler() {
          public void handle(WindowEvent we) {
              System.out.println("Stage is closing");
          }
      }); 
    

提交回复
热议问题