Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法在 JavaFX 中设置自定义关闭操作。我从 Swing 中知道这个,但在 JavaFX 中找不到它。如果您通过按 [X] 在此处关闭窗口,它将自动关闭。
您可以使用该onCloseRequest属性:
onCloseRequest
stage.setOnCloseRequest(new EventHandler<WindowEvent>() { @Override public void handle(WindowEvent t) { System.out.println("CLOSING"); } });
请注意,如果您调用Platform.exit()代码,这将不起作用。
Platform.exit()