1

I would like to use Timer inside Scout classes to change UI of scout elements.

For example : I have some label and I would like to change value after some time :

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

  @Override
  public void run() {

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

This give me error :

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

witch I understand because you shouldn't change UI outside its thread. But now I have trouble to return on UI thread because it is not SWT thread nor SWING thread. (Scout UI is wrapper for both)

How can I run Timer in Scout, or how to get UI thread in Scout ?

Marko

Marko Zadravec
  • 8,298
  • 10
  • 55
  • 97

1 Answers1

1

What you want is to perform the change of the UI in a ClientSyncJob:

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

As usual when working on the UI-thread, be careful to avoid unnecessary work on the SyncJob.

(The counterpart, when you wish to start asynchronous work from the UI thread, would be a ClientAsyncJob.)

Patrick
  • 4,720
  • 4
  • 41
  • 71