org.eclipse.swt.SWTException: Invalid thread access

来源:互联网 发布:全国小龙虾消费数据 编辑:程序博客网 时间:2024/04/30 22:12

在SWT程序中, SWT会自动创建一个用户界面线程,非用户界面线程不能直接操作用户界面线程
要想在另外一个线程中尝试修改用户界面,应采用一下方法:
   // If this is the UI thread, then make the change.
   if (Display.getCurrent() != null) {
      // 修改界面的代码
      return;
   }
   // otherwise, redirect to execute on the UI thread.
   Display.getDefault().asyncExec(new Runnable() {
      public void run() {
        // 修改界面的代码
      }
   });