在JavaFX上,如何隐藏舞台而不处理它并关闭应用程序? [英] On JavaFX, how to hide stage without disposing it and closing the application?

查看:20
本文介绍了在JavaFX上,如何隐藏舞台而不处理它并关闭应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个向用户显示初级阶段的应用程序,如果用户关闭阶段,而不是完成应用程序,它应该只是隐藏阶段以供以后使用.在 Swing 上,我们可以将 setVisible(false) 调用到 JFrame 或 JDialog,但如何在 JavaFX 上执行此操作?

I need to creat an app that shows the primary stage to the user, and if the user closes the stage, instead of finishing the application, it should just hide the stage for later use. On swing we could just call setVisible(false) to a JFrame or JDialog, but how to do it on JavaFX?

推荐答案

JavaFX 工具包启动后,默认情况下会在最后一个可见窗口关闭时关闭.

Once the JavaFX toolkit has started, by default it will close down when the last visible window is closed.

为了防止这种情况,您可以调用

To prevent this, you can call

Platform.setImplicitExit(false);

您通常在 start(...) 方法中执行此操作,尽管它可以从任何线程调用.

You typically do this in your start(...) method, though it can be called from any thread.

要退出应用程序,您需要调用

To exit the application, you would then need to call

Platform.exit();

(因为应用程序不再自动退出).

(as the application no longer exits automatically).

这篇关于在JavaFX上,如何隐藏舞台而不处理它并关闭应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆