JavaFX 2.0:关闭阶段(窗口) [英] JavaFX 2.0: Closing a stage (window)

查看:39
本文介绍了JavaFX 2.0:关闭阶段(窗口)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 JavaFX 2.0 中制作应用程序.在我的主窗口中,我正在启动一个带有一些设置的新窗口.调整完设置后,我想按下保存更改"之类的按钮.

I'm making a application in JavaFX 2.0. From my main window I am starting a new window with some settings. After I am done adjusting the settings I want to press a button like "Save changes".

我想要这个按钮来保存更改并关闭窗口.关闭我的意思是杀死它,而不是将它放在背景中或设置可见性.我读过一个方法 Stage.close()

I would like this button to save the changes and close the window. By closing i mean killing it, not placing it in the background or setting the visibility. I've read about a method Stage.close()

http://docs.oracle.com/javafx/2.0/api/javafx/stage/Stage.html

如您所见,它类似于 Hide() 方法,它只隐藏窗口,而不是关闭窗口.

As you can see it's similar to the method Hide(), which only hides the window, not closing it.

问:有人知道可以帮助我关闭窗口的任何方法或代码吗?

Q: Anybody knows any methods or have some code that would help me close a window?

非常感谢所有帮助.谢谢!

All help will be greatly appreciated. Thanks!

推荐答案

您链接的文档指出stage.close():

关闭此阶段.这个调用相当于hide().

Closes this Stage. This call is equivalent to hide().

由于 hide() 等价于 close() 并且 close() 关闭舞台,然后 hide() 也会关闭舞台.

As hide() is equivalent to close() and close() closes the stage, then hide() also closes the stage.

当应用程序中的所有阶段都隐藏(或关闭,如果您愿意,因为它是同一件事)时,应用程序将退出.我知道这令人困惑,但这正是 JavaFX 团队决定命名和实施操作的方式.

When all stages in an application are hidden (or closed if you like, because it is the same thing), the application exits. Confusing, I know, but that's just the way the JavaFX team decided to name and implement the actions.

如果需要,平台.setImplicitExit(boolean) 方法可用于关闭最后一个窗口关闭或隐藏时退出应用程序的默认行为.

If desired, the Platform.setImplicitExit(boolean) method can be used to switch off the default behaviour of exiting the application when the last window is closed or hidden.

那么问题来了,如何在不完全关闭的情况下隐藏舞台?

Then it comes to the question, How can we hide the stage without closing it completely?

我认为 hide() 或等效的 close() 方法不会完全"关闭舞台;就像释放与窗口相关的所有资源(只要您在某处保留对舞台的引用).我认为它只是使舞台不可见.您可能可以在调用 close() 之后调用 show() 并且窗口可能会再次可见(我没有尝试过).但是,如果您要这样做,那么调用 hide() 而不是 close() 会更直观.

I don't think hide() or the equivalent close() method will close the stage "completely" as in freeing up all resources related to the window (as long as you keep a reference to the stage around somewhere). I think it just makes it so that the stage is not visible. You could probably call show() after calling close() and the window would likely be made visible again (I didn't try it). Though, if you were to do that, then it would be more intuitive to call hide() rather than close().

我的猜测是,如果您不再保留对应用程序中某个阶段的任何引用并且该阶段已关闭或隐藏,那么每当其算法决定对这些资源进行垃圾回收时,JVM 可能会释放与该阶段相关的所有资源(再次我没有测试这个,它可能不会那样工作).

My guess is that if you no longer keep any references to a stage in your application and the stage is closed or hidden, then perhaps the JVM will release all resources related to the stage whenever its algorithm decides to garbage collect those resources (again I didn't test this and it may not work that way).

这篇关于JavaFX 2.0:关闭阶段(窗口)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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