Apache NetBeans
Apache NetBeans
Latest release

Apache NetBeans 23

Download

How to execute a long running task from an action without blocking the GUI?

The easy way if you might need to run a long task when some action is involved:

@ActionRegistration(asynchronous = true)
...
public void actionPerformed(ActionEvent ev) {
    if (isLongTaskRequired) {
        // maybe run a ProgressHandler
        doLongTask();
    }
    EventQueue.invokeLater(new Runnable() {
        @Override public void run() {
            // do domething with the gui
        }
    });
}

This way you don’t even need to care about threading yourself, GUI will be updated as long as the task is finished.

Taken from dev@platform.netbeans.org (Oct 2013)