我是靠谱客的博主 殷勤蜜蜂,最近开发中收集的这篇文章主要介绍java怎么关闭fxml窗口,如何关闭窗口关闭JavaFX应用程序?,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

In Swing you can simply use setDefaultCloseOperation() to shut down the entire application when the window is closed.

However in JavaFX I can't find an equivalent. I have multiple windows open and I want to close the entire application if a window is closed. What is the way to do that in JavaFX?

Edit:

I understand that I can override setOnCloseRequest() to perform some operation on window close. The question is what operation should be performed to terminate the entire application?

stage.setOnCloseRequest(new EventHandler() {

@Override

public void handle(WindowEvent event) {

stop();

}

});

The stop() method defined in Application class does nothing.

解决方案

The application automatically stops when the last Stage is closed. At this moment, the stop() method of your Application class is called, so you don't need an equivalent to setDefaultCloseOperation()

If you want to stop the application before that, you can call Platform.exit(), for example in your onCloseRequest call.

You can have all these information on the javadoc page of Application : http://docs.oracle.com/javafx/2/api/javafx/application/Application.html

最后

以上就是殷勤蜜蜂为你收集整理的java怎么关闭fxml窗口,如何关闭窗口关闭JavaFX应用程序?的全部内容,希望文章能够帮你解决java怎么关闭fxml窗口,如何关闭窗口关闭JavaFX应用程序?所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(50)

评论列表共有 0 条评论

立即
投稿
返回
顶部