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);

更多相关文章

  1. 字体图标的引入和通过媒体查询改变导航样式
  2. HTML样式和常用选择器
  3. 字体图标的引用和自定义样式/媒体查询的使用
  4. 数据库的CURD操作、PDO本质与原理的学习
  5. CSS之伪类选择器和简单盒子简单案例
  6. 伪类选择器与盒模型常用属性
  7. 伪类选择器-结构伪类、根据位置选择匹配
  8. 7.4——常用标签与应用场景之表格与单元格
  9. css伪类选择器和盒模型

随机推荐

  1. 一种绕过Android P对非SDK接口限制的简单
  2. Android webview注入自己的js代码(js传入f
  3. Android(安卓)MVP 模式:简单易懂的介绍方
  4. 第二部分:开发简要指南-第五章 支持不同的
  5. 关于android单元测试结合SAX解析xml文件
  6. 【Android的从零单排开发日记】之入门篇(
  7. 《Android移动应用基础教程》(Android Stu
  8. 年后陆续面试Android 15 家大厂,这个问题
  9. Android利用WebService查询手机号码归属
  10. android 玩转ContentProvider之三--实现一