JDK-8057903 : Key event can not be accepted when pressing esc + f11
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6u81
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2014-09-09
  • Updated: 2014-12-15
  • Resolved: 2014-10-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6u91Fixed
Description

When a program does the focus moving and key operation for dialogue at the 
same time, the dialogue comes not to accept key operations.

 

Comments
Suggested fix description from the bug reporter: This problem occurs when a focus is moving among light wight components and a process of displaying dialogue interrupts. To set KeyboardFocusManager.clearingCurrentLightweightRequests during focus moving means that when an other window becomes active, focus setting is done on the very window. So, we think the problem will be resolved by clearing request at the above timing. When WindowEvent of WINDOW_GAINED_FOCUS is notified and clearingCurrentLightweightRequests is set to false, this reported problem comes not to occur.
13-10-2014

Evaluation from the bug reporter: What we found are, (1) When focus is moving on the parent window, the event of key-pressed which opens a dialogue is issued. (2) The event of (1) is stored as deferred operation. (3) When the focus event on the parent window is proessed, the flag of no-op is set in retargetFocusEvent(). (4) The deferred operation of (2)( the key pressing event) starts. (5) When the dialogue is opened, Focus request is set to the dialogue itself. (6) Focus request is set for the component on the dialogue in WindowsEvent of times when the dialogue is opened (7) FocusEvent for the dialogue is issued. However, because the focus target is not renewed in retargetFocusEvent(), only the focus request of (5) is done and the focus request of (6) still remains. (8)Because FocusEvent for the focus request of (6) doesn't come, Key Event is kept being stored as deferred and not processed. When there are more than 2 requests for the same panel at (1) step, the no-op is set in retargetFocusEvent() at (3) step. The following stack trace(Sorry, this trace is in 6u75, not 6u81) is gotten at step(7). line#43 and line#36 correspond the above-mentioned (3) and (4) respectively. --- [1] java.awt.KeyboardFocusManager.retargetFocusEvent (KeyboardFocusManager.java:2,890) [2] java.awt.Component.dispatchEventImpl (Component.java:4,557) [3] java.awt.Container.dispatchEventImpl (Container.java:2,098) [4] java.awt.Window.dispatchEventImpl (Window.java:2,492) [5] java.awt.Component.dispatchEvent (Component.java:4,520) [6] java.awt.EventQueue.dispatchEventImpl (EventQueue.java:681) [7] java.awt.EventQueue.access$400 (EventQueue.java:81) [8] java.awt.EventQueue$2.run (EventQueue.java:640) [9] java.awt.EventQueue$2.run (EventQueue.java:638) [10] java.security.AccessController.doPrivileged (native method) [11] java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86) [12] java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:97) [13] java.awt.EventQueue$3.run (EventQueue.java:654) [14] java.awt.EventQueue$3.run (EventQueue.java:652) [15] java.security.AccessController.doPrivileged (native method) [16] java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86) [17] java.awt.EventQueue.dispatchEvent (EventQueue.java:651) [18] java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269) [19] java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184) [20] java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:178) [21] java.awt.Dialog$1.run (Dialog.java:1,052) [22] java.awt.Dialog$3.run (Dialog.java:1,104) [23] java.security.AccessController.doPrivileged (native method) [24] java.awt.Dialog.show (Dialog.java:1,102) [25] EscDialog$MyKeyAdapter.keyPressed (EscDialog.java:35) [26] java.awt.Component.processKeyEvent (Component.java:6,287) [27] javax.swing.JComponent.processKeyEvent (JComponent.java:2,809) [28] java.awt.Component.processEvent (Component.java:6,106) [29] java.awt.Container.processEvent (Container.java:2,040) [30] java.awt.Component.dispatchEventImpl (Component.java:4,692) [31] java.awt.Container.dispatchEventImpl (Container.java:2,098) [32] java.awt.Component.dispatchEvent (Component.java:4,520) [33] java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1,876) [34] java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:722) [35] java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1,000) [36] java.awt.DefaultKeyboardFocusManager.pumpApprovedKeyEvents(DefaultKeyboardFocusManager.java:810) [37] java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:916) [38] java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:523) [39] java.awt.Component.dispatchEventImpl (Component.java:4,564) [40] java.awt.Container.dispatchEventImpl (Container.java:2,098) [41] java.awt.Component.dispatchEvent (Component.java:4,520) [42] java.awt.KeyboardFocusManager.dispatchAndCatchException(KeyboardFocusManager.java:2,582) [43] java.awt.KeyboardFocusManager.processCurrentLightweightRequests(KeyboardFocusManager.java:2,671) [44] java.awt.KeyboardFocusManager.retargetFocusEvent(KeyboardFocusManager.java:2,930) [45] java.awt.Component.dispatchEventImpl (Component.java:4,557) [46] java.awt.Container.dispatchEventImpl (Container.java:2,098) [47] java.awt.Window.dispatchEventImpl (Window.java:2,492) [48] java.awt.Component.dispatchEvent (Component.java:4,520) [49] java.awt.EventQueue.dispatchEventImpl (EventQueue.java:681) [50] java.awt.EventQueue.access$400 (EventQueue.java:81) [51] java.awt.EventQueue$2.run (EventQueue.java:640) [52] java.awt.EventQueue$2.run (EventQueue.java:638) [53] java.security.AccessController.doPrivileged (native method) [54] java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86) [55] java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:97) [56] java.awt.EventQueue$3.run (EventQueue.java:654) [57] java.awt.EventQueue$3.run (EventQueue.java:652) [58] java.security.AccessController.doPrivileged (native method) [59] java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86) [60] java.awt.EventQueue.dispatchEvent (EventQueue.java:651) [61] java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269) [62] java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184) [63] java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174) [64] java.awt.EventDispatchThread.pumpEvents (EventDispatchThread.java:169) [65] java.awt.EventDispatchThread.pumpEvents (EventDispatchThread.java:161) [66] java.awt.EventDispatchThread.run (EventDispatchThread.java:122)
13-10-2014

Standalone testcase: import javax.swing.*; import java.awt.*; import java.awt.event.*; public class EscDialog2 extends JFrame { JButton b, b2; public EscDialog2() { super(); setDefaultCloseOperation(EXIT_ON_CLOSE); b = new JButton("show"); setSize(320, 240); getContentPane().setLayout(new BorderLayout()); b.setBounds( 50, 75, 200, 50 ); b.addKeyListener( new MyKeyAdapter()); JPanel p = new JPanel(); p.setLayout(null); b2 = new JButton("show too"); b2.setBounds( 50, 140, 200, 50 ); b2.addKeyListener( new MyKeyAdapter()); p.add(b); p.add(b2); getContentPane().add(p, BorderLayout.CENTER); } public class MyKeyAdapter extends KeyAdapter { public void keyPressed(KeyEvent e) { if (e.getKeyCode() == e.VK_ESCAPE) { final Component c = (Component)e.getSource(); JOptionPane op = new JOptionPane("Test message", JOptionPane.PLAIN_MESSAGE, JOptionPane.YES_NO_OPTION); // enqueueKeyEvents set to Dialog itself at show(). JDialog d = op.createDialog(EscDialog2.this, "escdialog"); d.show(); } else if (e.getKeyCode() == e.VK_F11) { // Need to stack multiple Lightweight focus requests. final Component c = (Component)e.getSource(); c.transferFocus(); c.requestFocusInWindow(); } } } public static void main(String[] args) throws Exception { EscDialog2 obj = new EscDialog2(); obj.show(); Thread.sleep(1000); Robot r = new Robot(); while(true) { r.keyPress(KeyEvent.VK_ESCAPE); r.keyRelease(KeyEvent.VK_ESCAPE); r.keyPress(KeyEvent.VK_F11); r.keyRelease(KeyEvent.VK_F11); Thread.sleep(5); } } }
10-09-2014