src/share/classes/com/sun/java/swing/plaf/windows/WindowsRootPaneUI.java

Print this page

        

@@ -28,10 +28,12 @@
 import java.awt.Component;
 import java.awt.Container;
 import java.awt.Event;
 import java.awt.KeyEventPostProcessor;
 import java.awt.Window;
+import java.awt.Toolkit;
+import sun.awt.SunToolkit;
 
 import java.awt.event.ActionEvent;
 import java.awt.event.KeyEvent;
 
 import javax.swing.AbstractAction;

@@ -123,11 +125,19 @@
                 if(mbar == null && winAncestor instanceof JFrame) {
                     mbar = ((JFrame)winAncestor).getJMenuBar();
                 }
                 JMenu menu = mbar != null ? mbar.getMenu(0) : null;
 
-                if (menu != null) {
+                // Skip menu activation if the KeyEvent originated before
+                // the latest window deactivation.
+                boolean skip = false;
+                Toolkit tk = Toolkit.getDefaultToolkit();
+                if (tk instanceof SunToolkit) {
+                    skip = ev.getWhen() <= ((SunToolkit)tk).getDeactivationTime(winAncestor);
+                }
+
+                if (menu != null && !skip) {
                     MenuElement[] path = new MenuElement[2];
                     path[0] = mbar;
                     path[1] = menu;
                     msm.setSelectedPath(path);
                 } else if(!WindowsLookAndFeel.isMnemonicHidden()) {