我有一个 Swing 应用程序的问题,由于我目前无法识别的原因,有时会通过文本输入字段获得焦点。我怀疑某种竞争条件,但我看不出是什么导致了焦点事件。
该字段附加了一个焦点侦听器,因此可以直接向 focusGained() 事件处理程序添加断点。当我这样做时,我可以看到底层事件又包含 CausedFocusEvent.Cause 的一个实例。名称字段设置为“激活”。
查看堆栈跟踪,我可以看到以下内容:
Thread [AWT-EventQueue-0] (Suspended (breakpoint at line 174 in MyPanel$3))
MyPanel$3.focusGained(FocusEvent) line: 174
AWTEventMulticaster.focusGained(FocusEvent) line: not available
InputField(Component).processFocusEvent(FocusEvent) line: not available
InputField(Component).processEvent(AWTEvent) line: not available
InputField(Container).processEvent(AWTEvent) line: not available
InputField(Component).dispatchEventImpl(AWTEvent) line: not available
InputField(Container).dispatchEventImpl(AWTEvent) line: not available
InputField(Component).dispatchEvent(AWTEvent) line: not available
DefaultKeyboardFocusManager(KeyboardFocusManager).redispatchEvent(Component, AWTEvent) line: not available
DefaultKeyboardFocusManager.typeAheadAssertions(Component, AWTEvent) line: not available
DefaultKeyboardFocusManager.dispatchEvent(AWTEvent) line: not available
InputField(Component).dispatchEventImpl(AWTEvent) line: not available
InputField(Container).dispatchEventImpl(AWTEvent) line: not available
InputField(Component).dispatchEvent(AWTEvent) line: not available
SunToolkit$1.run() line: not available
PeerEvent(InvocationEvent).dispatch() line: not available
EventQueue.dispatchEventImpl(AWTEvent, Object) line: not available
EventQueue.access$200(EventQueue, AWTEvent, Object) line: not available
EventQueue$3.run() line: not available
EventQueue$3.run() line: not available
AccessController.doPrivileged(PrivilegedAction<T>, AccessControlContext) line: not available [native method]
ProtectionDomain$1.doIntersectionPrivilege(PrivilegedAction<T>, AccessControlContext, AccessControlContext) line: not available
EventQueue.dispatchEvent(AWTEvent) line: not available
EventDispatchThread.pumpOneEventForFilters(int) line: not available
EventDispatchThread.pumpEventsForFilter(int, Conditional, EventFilter) line: not available
EventDispatchThread.pumpEventsForHierarchy(int, Conditional, Component) line: not available
EventDispatchThread.pumpEvents(int, Conditional) line: not available
EventDispatchThread.pumpEvents(Conditional) line: not available
EventDispatchThread.run() line: not available
请注意,InputField 是 JTextField 的子类,它与文本的呈现相关的细微变化。
我可以从堆栈跟踪中得知 EDT 上的某些内容导致 MyPanel 中的 InputField 获得焦点。
是否有任何进一步的信息可以让我了解为什么该组件获得了焦点?