Refresh SWT elements periodicaly

To refresh elements in a SWT Widget is quite easy. You don’t need to use display.syncExec(). Just use the display.timerExec() method recoursivly. Here is a simple codesnip for refreshing a TreeView:

The createPartControl Method of your ViewPart class
(or any other startup method of the control) :

public void createPartControl(Composite parent) {
  ... init the control

  //start refresh
  refresh(parent.getDisplay());
}

The refresh method:
private void refresh(Display display){
  display.timerExec(ddtsPollDelay,new Runnable() {
     public void run() {
        ... update code ...

        //recursive call
        refreshTree();
     }
  });
}

SWT is nice and easy…

Leave a Reply

Your email address will not be published.

*