Invalid Thread Access Error with Java SWT

It is thrown because your listener code is called from outside the SWT Display thread. You run code on the display thread like this:

Display.getDefault().syncExec(new Runnable() {
    public void run() {
        // ...
    }
});

or, asynchronously:

Display.getDefault().asyncExec(new Runnable() {
    public void run() {
        // ...
    }
});

Maybe this will help you:

FAQ Why do I get an invalid thread access exception? https://wiki.eclipse.org/FAQ_Why_do_I_get_an_invalid_thread_access_exception%3F