United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-8000327 [macosx] ActionListener called twice for JMenuItem using ScreenMenuBar
JDK-8000327 : [macosx] ActionListener called twice for JMenuItem using ScreenMenuBar

Details
Type:
Backport
Submit Date:
2012-10-02
Status:
Closed
Updated Date:
2013-08-09
Project Name:
JDK
Resolved Date:
2012-10-09
Component:
client-libs
OS:
Sub-Component:
javax.swing
CPU:
Priority:
P3
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:
7u10 (b12)

Related Reports
Backport:
Relates:
Relates:

Sub Tasks

Description
FULL PRODUCT VERSION :
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.

                                    

Comments
7u10-critical-request: Netbeans affected. This bug and 8000283 should be fixed simultaneously. Note that 8000283 already pushed to 7u10. 
                                     
2012-10-02
Need SQE approval comments in bug report.
                                     
2012-10-04
Email sent to Pavel Stepanov:
Hi,
We need SQE approval in order to push the fix for 8000327 into 7u10. Note, that this fix has already been pushed into 7u10 b8 and found to be OK. 
                                     
2012-10-05
SQE OK
                                     
2012-10-05
Issue about test creation
                                     
2012-10-29
/test: http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/509b3b4910ef
                                     
2012-11-19



Hardware and Software, Engineered to Work Together