Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8040628

[macosx] Meta-Enter (Cmd-Enter) native menu item accelerator produces two ActionEvents

    Details

    • Subcomponent:
    • OS:
      os_x
    • Verification:
      Verified

      Description

      FULL PRODUCT VERSION :
      java version "1.7.0_40"
      Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
      Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      OS X 10.8.5 (12F37)

      A DESCRIPTION OF THE PROBLEM :
      When a java application is using "apple.laf.useScreenMenuBar" to enable native menu, the accelerator keystroke combination Cmd-Enter (or Meta-Enter) will produce two ActionEvents

      REGRESSION. Last worked in version 6u45


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.JMenu;
      import javax.swing.JMenuItem;
      import javax.swing.JCheckBoxMenuItem;
      import javax.swing.JRadioButtonMenuItem;
      import javax.swing.ButtonGroup;
      import javax.swing.JMenuBar;
      import javax.swing.KeyStroke;
      import javax.swing.ImageIcon;

      import javax.swing.JPanel;
      import javax.swing.JTextArea;
      import javax.swing.JScrollPane;
      import javax.swing.JFrame;

      public class MenuDemo implements ActionListener {
      JTextArea output;
      JScrollPane scrollPane;
      String newline = "
      ";

      public JMenuBar createMenuBar() {
      JMenuBar menuBar;
      JMenu menu;
      JMenuItem menuItem;

      menuBar = new JMenuBar();

      menu = new JMenu("A Menu");
      menu.setMnemonic(KeyEvent.VK_A);
      menuBar.add(menu);

      menuItem = new JMenuItem("Meta-Enter", KeyEvent.VK_E);
      menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, ActionEvent.META_MASK));
      menuItem.addActionListener(this);
      menu.add(menuItem);

      menuItem = new JMenuItem("Meta-E", KeyEvent.VK_E);
      menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.META_MASK));
      menuItem.addActionListener(this);
      menu.add(menuItem);

      menuItem = new JMenuItem("ALT-Enter", KeyEvent.VK_E);
      menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, ActionEvent.ALT_MASK));
      menuItem.addActionListener(this);
      menu.add(menuItem);return menuBar;
      }

      public Container createContentPane() {
      JPanel contentPane = new JPanel(new BorderLayout());
      contentPane.setOpaque(true);

      output = new JTextArea(5, 30);
      output.setEditable(false);
      scrollPane = new JScrollPane(output);

      contentPane.add(scrollPane, BorderLayout.CENTER);
      return contentPane;
      }

      public void actionPerformed(ActionEvent e) {
      JMenuItem source = (JMenuItem)(e.getSource());
      String s = "Action event detected." + newline + " Event source: " + source.getText();
      output.append(s + newline);
      output.setCaretPosition(output.getDocument().getLength());
      }

      private static void createAndShowGUI() {
      System.setProperty("apple.laf.useScreenMenuBar", "true");

      JFrame frame = new JFrame("MenuDemo");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      MenuDemo demo = new MenuDemo();
      frame.setJMenuBar(demo.createMenuBar());
      frame.setContentPane(demo.createContentPane());

      frame.setSize(450, 260);
      frame.setVisible(true);
      }

      public static void main(String[] args) {
      javax.swing.SwingUtilities.invokeLater(new Runnable() {
      public void run() {
      createAndShowGUI();
      }
      });
      }
      }
      ---------- END SOURCE ----------

        Attachments

          Activity

            People

            • Assignee:
              amalinko Artem Malinko (Inactive)
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: