title: Focus debugging in Java
body: <h3>The problem:</h3>
  <p>I am trying to debug some focus-related problems in my Java Swing application. There are times when some components seem to be grabbing focus and I cannot figure out where in code this is happening.</p>
  <h3>What I have tried:</h3>
  <ul>
  <li><p>A <code>VetoableChangeListener</code> with <code>KeyboardFocusManager</code> (for <code>focusOwner</code>). This does give me information about which components lose and gain focus, but it does not help me pin point where in code the focus is being requested.</p>
  </li>
  <li><p>A custom <code>KeyboardFocusManager</code>. But in that too I can intervene only when it receives events. By that time the call stack of the call to <code>requestFocus</code> is already lost.</p>
  </li>
  <li><p>A custom <code>EventQueue</code>. But there too I am able to intervene in the <code>dispatchEvent</code> method which is again called from the EDT. Again the call stack is lost (interestingly the <code>postEvent(AWTEvent)</code> is not called).</p>
  </li>
  </ul>
  <h3>Question:</h3>
  <p>What I am looking for is the call stack when the call to <code>requestFocusInWindow</code> is made. Is it possible to get this information. Perhaps, if I could redefine the method used to post the event in <code>EventQueue</code>, then I can print the stack dump. However the <code>EventQueue.postEvent(AWTEvent)</code> does not get invoked.</p>
  <p>Can anyone suggest a solution which will help me get the state of the stack when the call to <code>requestFocus</code> or <code>requestFocusInWIndow</code> may have been made?</p>