Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update SWT GUI from another thread in Java

I am writing a desktop application using SWT. What is the simplest way to update GUI controls from another thread?

like image 787
Michał Ziober Avatar asked Aug 26 '09 09:08

Michał Ziober


1 Answers

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();
        }
      }
    });
  }
  • More here
like image 91
McDowell Avatar answered Oct 02 '22 19:10

McDowell