如何通过右键单击->关闭窗口检测窗口关闭?

发布于 2024-12-13 03:09:22 字数 280 浏览 2 评论 0原文

当有人通过右键单击应用程序并执行“关闭窗口”从任务栏(而不是直接从应用程序本身)关闭基于桌面的 Java/JavaFx 应用程序时,是否会触发一个事件?

目前,如果我从任务栏关闭窗口,应用程序窗口将关闭,但进程不会被终止并继续在后台运行。我想完全关闭应用程序,以便应用程序中的嵌入式 Derby DB 断开连接。

我尝试过Stage的setOnHiding()setOnCloseRequest()和其他类似的方法,但没有效果。

感谢您的帮助!

Is there an event that gets fired when somebody closes a desktop-based Java/JavaFx application from the task bar (and not directly from the application itself) by right clicking on the application and executing Close Window?

Currently, if I close the window from the taskbar, the application window gets closed but the process does not get killed and keeps running in the background. I want to shut down the application completely, so that the Embedded Derby DB within the application gets disconnected.

I have tried the Stage's setOnHiding(), setOnCloseRequest() and other similar methods, but to no avail.

Thanks for all your help !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半步萧音过轻尘 2024-12-20 03:09:22

您可以尝试使用ShutdownHook来释放应用程序资源。

Runtime.getRuntime().addShutdownHook(...);

You can try to use ShutdownHook to free application resources.

Runtime.getRuntime().addShutdownHook(...);
墨落成白 2024-12-20 03:09:22
JFrame f = new JFrame();
f.addWindowListener(new WindowAdapter()) {
            @Override
            public void windowClosing(WindowEvent e) {
                // write your code here 
            }
}
JFrame f = new JFrame();
f.addWindowListener(new WindowAdapter()) {
            @Override
            public void windowClosing(WindowEvent e) {
                // write your code here 
            }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文