-
Bug
-
Resolution: Fixed
-
P3
-
7
-
b58
-
x86
-
os_x
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8018964 | 7u45 | Leonid Romanov | P3 | Closed | Fixed | b01 |
JDK-2229826 | 7u40 | Leonid Romanov | P3 | Closed | Fixed | b08 |
JDK-8000327 | 7u10 | Leonid Romanov | P3 | Closed | Fixed | b12 |
java version "1.7.0_04-ea"
Java(TM) SE Runtime Environment (build 1.7.0_04-ea-b19)
Java HotSpot(TM) 64-Bit Server VM (build 23.0-b20, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Mac OS X 10.7.3
A DESCRIPTION OF THE PROBLEM :
When the ScreenMenuBar is activated using System.setProperty("apple.laf.useScreenMenuBar", "true"); and the registered Accelerator Key for a JMenuItem is pressed, the ActionListener is called twice.
REGRESSION. Last worked in version 6u31
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Activate the usage of the Screen Menu Bar
System.setProperty("apple.laf.useScreenMenuBar", "true");
Create a JFrame with a JMenuBar, JMenu and a JMenuItem and register a hotkey to the JMenuItem using setAccelerator and add an ActionListener.
Start the test application and press the Hotkey.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Having the ActionListener called once per pressed hotkey.
ACTUAL -
The ActionListener its called twice.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.reflect.InvocationTargetException;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
public class Test extends JFrame {
public Test() {
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
JMenuItem openItem = new JMenuItem("Open");
openItem.setAccelerator(KeyStroke.getKeyStroke('O', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
openItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("i was called");
}
});
fileMenu.add(openItem);
menuBar.add(fileMenu);
setJMenuBar(menuBar);
pack();
setVisible(true);
}
public static void main(String[] args) throws InvocationTargetException, InterruptedException {
System.setProperty("apple.laf.useScreenMenuBar", "true");
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
new Test();
}
});
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Do not use the ScreenMenuBar.
- backported by
-
JDK-2229826 [macosx] ActionListener called twice for JMenuItem using ScreenMenuBar
-
- Closed
-
-
JDK-8000327 [macosx] ActionListener called twice for JMenuItem using ScreenMenuBar
-
- Closed
-
-
JDK-8018964 [macosx] ActionListener called twice for JMenuItem using ScreenMenuBar
-
- Closed
-
- duplicates
-
JDK-7179290 [macosx] JMenuItem kicks an action 2 times with single key input.
-
- Closed
-
- relates to
-
JDK-8002114 fix failed for JDK-7160951: [macosx] ActionListener called twice for JMenuItem using ScreenMenuBar
-
- Closed
-
-
JDK-8000283 [macosx] Main menu shortcuts not displayed (7u6 regression)
-
- Closed
-
-
JDK-8152492 [macosx swing] double key event actions when using Mac menubar
-
- Resolved
-
-
JDK-8139169 [macosx] Action registered for keyboard shortcut is called twice
-
- Resolved
-