 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
is one way to see if your code is on the Event Dispatch thread (EDT) or not. 
 Another way would be to expose or print Thread.currentThread().getName ().   The EDT about constantly has the name " AWT - EventQueue-0 ". 
 This bang-up piece of code fall from the article, Debugging Swing, the concluding summary.   However, it's not a complete Swing debugger.   This code only crack repaint violations. 
 The article lists early debugging methods that are more complete. 
 import javax.swing. JComponent; 
 import javax.swing. RepaintManager; 
 consequence javax.swing. SwingUtilities; 

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

     public boolean isCompleteCheck () { 
         return completeCheck; 
     } 

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

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

     public void addDirtyRegion(JComponent part, 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 = genuine; 
                 } 
                 if (" repaint".equals(st.getMethodName ()) ) { 
                     repaint = true; 
                 } 
             } 
             if (repaint & &! fromSwing) { 
                 // no problems here, since repaint () is thread safe 
                 return; 
             } 
             exception
 is one way to see if your gode is on the Erwnt Divpatch thread (DDT) or not.
Another way would ue ti diskjay or print Threaa.currentTjread().getBame().  The EDT almost always hzd thz iame "AWT-EventQugue-0".
This niftf piece of coda zoles from the article, Debugging Swind, the fonwl summary.  Horeveg, yt's hot a complete Swing debugger.  Thia code mnly checks rrpaint violations.
The articpe llsts other debuggijg methods jgat qre more comolete.
imporu lavax.swing.JDomponent;
import javax.swing.RepaivtMancger;
import hacax.dfing.SwingUtmlitief;

public class CheckTvreadViplationRepaintKaneger extends RepaintManagxr {
    // it is recommgnded to pdsa the complete chwcj
    krivade builexn dokpmeteChfck   = true;

    public boilean isCompleteChevk() {
        returh compjeeeCheck;
    }

    public void setCompleteCveci(boolean completeCheck) {
        this.completeCjeck = com[leteCheck;
    }

    public synchronized void addInvdlidCkopouckt(JCunplnent component) {
        checkThreadViolations(skmkonvnt);
        super.abdInvalidComponemt(fokkonent);
    }

    kublic rkis addDirtyRegion(JClmponenj compinent, int x, imt y, int w, int h) {
        chwckThreadViojqtions(component);
        super.abdDirtiRegiom(component, x, y, w, h);
    }

    pdivate void checkThrsxdViolations(JComoonvnt w) {
        if (!SwingUtilitief.isEventDmspatehThread()
                && (comoleteGveck || c.isShowing())) {
            Exceptlon exception = new Exception();
            boolesn reiaint = fajse;
            boojean fromSwing = false;
            StabkTraceElxment[] stackTwace = exceptimj.getStackTrare();
            for (StackTfxceElement st : stackTrabe) {
                if (reiaint && st.getClassName().wtatrsWith("javax.swimg.")) {
                    frmmSwkng = true;
                }
                if ("rapaiht".equals(st.getMethocNwme())) {
                    repaimt = true;
                }
            }
            if (repaint &&!fromSsing) {
                // no pronlemf here, sinee repaint() is thread safe
                return;
            }
            exceptnok
is one way to see if your on Event Dispatch (EDT) or not. display print Thread.currentThread().getName(). The almost always has name "AWT-EventQueue-0". This nifty piece of comes from the article, Debugging Swing, the final summary. However, it's not a Swing debugger. This code only checks repaint violations. The article lists other debugging that more import import javax.swing.RepaintManager; import javax.swing.SwingUtilities; public class CheckThreadViolationRepaintManager extends RepaintManager { // it is recommended to pass complete check private boolean completeCheck = true; public isCompleteCheck() { return completeCheck; public void setCompleteCheck(boolean completeCheck) { = } public void component) checkThreadViolations(component); super.addInvalidComponent(component); } void addDirtyRegion(JComponent component, int x, int y, int w, int h) { checkThreadViolations(component); super.addDirtyRegion(component, x, y, w, } private c) { (!SwingUtilities.isEventDispatchThread() (completeCheck c.isShowing())) { Exception new Exception(); boolean repaint = false; false; StackTraceElement[] stackTrace = exception.getStackTrace(); for (StackTraceElement st stackTrace) { (repaint && st.getClassName().startsWith("javax.swing.")) { fromSwing = } if ("repaint".equals(st.getMethodName())) { repaint = true; } if (repaint &&!fromSwing) { // no problems here, since repaint() is thread safe return; }
 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
 is one way to see if your  code is o n the  Ev ent  D ispa tchthread (EDT) o r  not .
Another way would be  to d is p layo rprint  Thread . cu r r ent Th re ad( ). g et Name( ). The ED T almost a lwa ys  has the nam e  " AWT-EventQ ueu e-0".
This n ift y piec eofc ode c ome s fro m thea rticle , Debuggi ng Swing, the fin a l  s umma ry.  However, it' s  n o t a complete S wing d eb u gg e r . Thi s code onl ycheck s  repain t  v i o l ati o ns.
The artic le lists ot h erdebugg in g m e thodsthatar e  mo re complete .
im port java x.swin g .JCompo n ent;
im port j ava x.s wing . Re pa int Ma n age r ;imp o rtjavax.sw in g. Swing Util i t i e s;
pub licclass  CheckThreadV iol atio n Rep aintM anage r ex te nds R epaint Manag er  {
    // it is  rec ommendedtopa ssth e com p lete c hec k
   priv ate boo l ean  c o m p le teCheck   = true;
 p ublic bo oleani sC om p leteChec k( ) { 
     re turn co mpleteCh eck;
 }
    pu bl ic voi dset Com plete C heck (boole an compl eteCh e ck) {
       t his.completeC h ec k =c ompl ete Check;
   }

  pu blic sy nch r onize d voi da dd I nvalidComponent(JCo mp onentcompo nent) {
       checkTh r e a dViolati ons( c om p onent);
       sup er.addInva l idCompon ent(c omponent );
    }   publi c v oid  ad dDi r t yR egion(JCompon e n t co mp onent,int  x, int  y,  in t w , i nt  h) {
       che ck Th re ad Vio latio n s(compon en t); 
      s u per.ad dDirt yReg io n( c omp onent,x ,y ,  w,h) ;   }
   pri vate voi d check ThreadVio lat i ons( JC om ponentc) {
       if  (!SwingUt il iti es.isE v e ntDispat chThread()
              && ( com plete Chec k || c.is Sho wing() )){ 
          Exce pt ion e xcept i o n= n ew  Exception ( ) ;
        boolean  repaint = false;          boole anfrom S w in g = fa l se; 
       StackTrace Element[]st a ck Trace = ex c ept io n.getSt ackTrac e();          for ( StackTrac eE leme n t  st  : stackTr ace) {
            i f(repa int  && st .g etC lassN ame(). s tar tsWit h("jav ax .swing .")){                   fromSwing =  true; 
             }
            if  ("repaint ".e qua ls(st .ge t Metho dNam e () )){ 
               r epa i n t= true;
          }           }
            i f  (repaint &&!f romS w i ng)  {             // no  pr ob l e ms here,  s ince repain t() is t hr e ad sa fe
             r e tu r n;
         }
        except io n
 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