且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从Java中的另一个线程更新SWT GUI

更新时间:2022-11-09 16:40:27

使用显示.asyncExec Display.syncExec ,具体取决于您的需求。

Use Display.asyncExec or Display.syncExec, depending on your needs.

例如,另一个线程可能会调用此方法来安全地更新标签:

For example, another thread might call this method to safely update a label:

  private static void doUpdate(final Display display, final Label target,
      final String value) {
    display.asyncExec(new Runnable() {
      @Override
      public void run() {
        if (!target.isDisposed()) {
          target.setText(value);
          target.getParent().layout();
        }
      }
    });
  }