Q:

How to check a Swing application for correct use of the EDT (Event DIspatch Thread)

I have found many tutorials and examples on using the EDT correctly, I would however like to hear how one should go the other way around: check a complex application which has a Swing GUI and many functionalities involving long network operations and find where the EDT is improperly used.
I have found that
SwingUtilities.isEventDispatchThread()

could be used to check whether one piece of code is inside the EDT or not, so I could check that all long operations don't happen to be inside places where SwingUtilities.isEventDispatchThread() returns true.
Is it right? is there something better I could to in a way debug the whole application in search of incorrect use of the EDT?
Thank you.

A:

Is it right?

Yes, checking the value of SwingUtilities.isEventDispatchThread() is one way to see if your code is on the Event Dispatch thread (EDT) or not.
Another way would be to display or print Thread.currentThread().getName().  The EDT almost always has the name "AWT-EventQueue-0".
This nifty piece of code comes from the article, Debugging Swing, the final summary.  However, it's not a complete Swing debugger.  This code only checks repaint violations.
The article lists other debugging methods that are more complete.
import javax.swing.JComponent;
import javax.swing.RepaintManager;
import javax.swing.SwingUtilities;

public class CheckThreadViolationRepaintManager extends RepaintManager {
    // it is recommended to pass the complete check
    private boolean completeCheck   = true;

    public boolean isCompleteCheck() {
        return completeCheck;
    }

    public void setCompleteCheck(boolean completeCheck) {
        this.completeCheck = completeCheck;
    }

    public synchronized void addInvalidComponent(JComponent component) {
        checkThreadViolations(component);
        super.addInvalidComponent(component);
    }

    public void addDirtyRegion(JComponent component, int x, int y, int w, int h) {
        checkThreadViolations(component);
        super.addDirtyRegion(component, x, y, w, h);
    }

    private void checkThreadViolations(JComponent c) {
        if (!SwingUtilities.isEventDispatchThread()
                && (completeCheck || c.isShowing())) {
            Exception exception = new Exception();
            boolean repaint = false;
            boolean fromSwing = false;
            StackTraceElement[] stackTrace = exception.getStackTrace();
            for (StackTraceElement st : stackTrace) {
                if (repaint && st.getClassName().startsWith("javax.swing.")) {
                    fromSwing = true;
                }
                if ("repaint".equals(st.getMethodName())) {
                    repaint = true;
                }
            }
            if (repaint && !fromSwing) {
                // no problems here, since repaint() is thread safe
                return;
            }
            exception.printStackTrace();
        }
    }
}

