The problem:
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.
What I have tried:
A
VetoableChangeListener
withKeyboardFocusManager
(forfocusOwner
). 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.A custom
KeyboardFocusManager
. But in that too I can intervene only when it receives events. By that time the call stack of the call torequestFocus
is already lost.A custom
EventQueue
. But there too I am able to intervene in thedispatchEvent
method which is again called from the EDT. Again the call stack is lost (interestingly thepostEvent(AWTEvent)
is not called).
Question:
What I am looking for is the call stack when the call to requestFocusInWindow
is made. Is it possible to get this information. Perhaps, if I could redefine the method used to post the event in EventQueue
, then I can print the stack dump. However the EventQueue.postEvent(AWTEvent)
does not get invoked.
Can anyone suggest a solution which will help me get the state of the stack when the call to requestFocus
or requestFocusInWIndow
may have been made?