1

我想在 Scout 类中使用 Timer 来更改 Scout 元素的 UI。

例如:我有一些标签,我想在一段时间后更改值:

  Timer timer = new Timer();
  timer.schedule(new TimerTask() {

  @Override
  public void run() {

    myLabel.setValue("some value")
    }
 }, 1000 * 4);

这给了我错误:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: queueing rwt runnable from outside scout thread

女巫我理解,因为您不应该在其线程之外更改 UI。但是现在我无法返回 UI 线程,因为它不是 SWT 线程也不是 SWING 线程。(Scout UI 是两者的包装)

如何在 Scout 中运行 Timer,或者如何在 Scout 中获取 UI 线程?

马尔科

4

1 回答 1

1

您想要的是在 a 中执行 UI 的更改ClientSyncJob

new ClientSyncJob("Perform UI Change", ClientSyncJob.getCurrentSession()) {
    @Override
    protected void runVoid(IProgressMonitor monitor) throws Throwable {
        // Your changes for the UI go here
    }
}.schedule();

像往常一样在 UI 线程上工作时,请注意避免在 SyncJob 上进行不必要的工作。

(对应的,当您希望从 UI 线程开始异步工作时,将是一个ClientAsyncJob.)

于 2015-08-21T05:06:30.583 回答