如何让我的基本SWT应用程序在Mac OS X 10.5.6中正常退出?
I have the following SWT test code:
我有以下SWT测试代码:
public static void main(String[] args) {
shell = new Shell();
shell.setText(APP_NAME + " " + APP_VERSION);
shell.addShellListener(new ShellListener() {
public void shellActivated(ShellEvent event) { }
public void shellClosed(ShellEvent event) { exit(); }
public void shellDeactivated(ShellEvent event) { }
public void shellDeiconified(ShellEvent event) { }
public void shellIconified(ShellEvent event) { }
});
shell.open();
display = shell.getDisplay();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
My exit() method is as follows:
我的exit()方法如下:
private void exit() {
System.exit(0);
}
I try to quit the application by closing the shell ("window") or by pulling down the application menu (labeled "SWT") and selecting "Quit".
我尝试通过关闭shell(“窗口”)或下拉应用程序菜单(标记为“SWT”)并选择“退出”来退出应用程序。
When I do this, a SWT stub is left behind in the Dock and the SWT application has not actually exited. I have to manually terminate the SWT application through Eclipse or via Force Quit.
当我这样做时,一个SWT存根留在Dock中,并且SWT应用程序实际上没有退出。我必须通过Eclipse或Force Quit手动终止SWT应用程序。
I have tried this with the v3.4 and v3.5 SWT jars, under Eclipse 3.4.1 under Mac OS X 10.5.6 (Intel).
我已经尝试使用v3.4和v3.5 SWT jar,在Mac OS X 10.5.6(Intel)下的Eclipse 3.4.1下。
Is there additional work I need to do to be able to quit the application when I close the shell?
当我关闭shell时,是否需要做额外的工作才能退出应用程序?
2 个解决方案
#1
9
You are not releasing the native resources correctly - you have a resource leak.
您没有正确释放本机资源 - 您有资源泄漏。
You don't need to do this:
你不需要这样做:
private void exit() {
System.exit(0);
}
The main method will exit when the shell is disposed. If you must use an exit method, call it after you've disposed all SWT resources:
处理shell时,main方法将退出。如果必须使用退出方法,请在处置完所有SWT资源后调用它:
Display display = new Display();
try {
Shell shell = new Shell(display);
try {
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
} finally {
if (!shell.isDisposed()) {
shell.dispose();
}
}
} finally {
display.dispose();
}
System.exit(0);
更多相关文章
- 字体图标的引入和通过媒体查询改变导航样式
- HTML样式和常用选择器
- 字体图标的引用和自定义样式/媒体查询的使用
- 数据库的CURD操作、PDO本质与原理的学习
- CSS之伪类选择器和简单盒子简单案例
- 伪类选择器与盒模型常用属性
- 伪类选择器-结构伪类、根据位置选择匹配
- 7.4——常用标签与应用场景之表格与单元格
- css伪类选择器和盒模型