JDK-7179290 : [macosx] JMenuItem kicks an action 2 times with single key input.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: os_x
  • CPU: x86
  • Submitted: 2012-06-23
  • Updated: 2012-07-23
  • Resolved: 2012-07-23
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 8
8Resolved
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.7.0_05"
Java(TM) SE Runtime Environment (build 1.7.0_05-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Mac OS X 10.7.4

A DESCRIPTION OF THE PROBLEM :
The JMenuItem calls actionPerformed method of the action class 2 times if the accelerator key with the command key mask is set and the Mac's screen menu bar is used.


REGRESSION.  Last worked in version 7

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1, Execute the source code included.
 java MenuTestFrame

2, Push Command+n

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
It should output only one number.
ACTUAL -
It outputs 2 numbers.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.AbstractAction;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;


public class MenuTestFrame extends JFrame{
	public MenuTestFrame() {
		JMenuBar menuBar = new JMenuBar();
		JMenu menu = new JMenu("test");
		JMenuItem item = new JMenuItem(new TestAction());
		
		item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.META_MASK));
		menuBar.add(menu);
		menu.add(item);
		this.setJMenuBar(menuBar);
	}
	
	class TestAction extends AbstractAction {
		public TestAction() {
			super("test");
		}
		
		@Override
		public void actionPerformed(ActionEvent arg0) {
			System.out.println(System.currentTimeMillis());
		}
		
	}
	
	public static void main(String[] args) {
		System.setProperty("apple.laf.useScreenMenuBar", "true");
		MenuTestFrame frame = new MenuTestFrame();
		frame.pack();
		frame.setVisible(true);
	}
}

---------- END SOURCE ----------