当JDialog是主窗口时,正确关闭Java程序 [英] Closing a java program properly when JDialog is the main window

查看:193
本文介绍了当JDialog是主窗口时,正确关闭Java程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序中有一个JDialog作为主窗口(最初是JFrame,但它显示在任务栏上是我不想要的).

I have a JDialog as the main window in my application (originally it was a JFrame but it showed in the taskbar which I didn't want).

当前我正在做

setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

,当我单击退出按钮时:

and when I click an exit button:

frame.dispose();

但是该过程似乎仍然在后台徘徊

But the process still seems to hang around in the background

JFrame的JFrame.EXIT_ON_CLOSE似乎可以满足我的要求.

JFrame had JFrame.EXIT_ON_CLOSE which seemed to do what I wanted.

如何正确关闭我的应用程序?

How can I close my application properly?

推荐答案

您可以添加

  System.exit(0);

您希望程序结束的位置,也许紧接在dispose()行之后.

where you want the program to end, maybe immediately after the dispose() line.

这篇关于当JDialog是主窗口时,正确关闭Java程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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