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

Apache NetBeans Wiki Index

Note: These pages are being reviewed.

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
    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 (Oct 2013)