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

Mnemonic key for a submenu item opens a different menu, if 2nd mnemonic is same.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P2 P2
    • None
    • 1.2.0
    • client-libs



      Name: clC74495 Date: 05/05/99


      /* FILE: /SwingMenuTests/IntlMenu.java (bts19328)

      When a menu is open, pressing the mnemonic key (alone, not Alt+Char)
      activates the associated submenu item (correct) but also drops open a menu
      that has the same accelerator character, if there is one (wrong).
      (Key-WIn32.html actually says that Alt+Char, not Char alone, activates the
       item. But it doesn't and shouldn't.)

      Steps to Reproduce:
      0. Place IntlMenuApp.java & IntlMenuFrame.java in the dir, \SwingMenuTests\, off of classpath, compile and run
      1.1 <Alt-M> //opens menu "Standard menu items"
      1.2 "r"
      //exp: the menu item "Rick" to get activated, and then the menu bar to lose focus
      //act: "Rick" correctly gets selected (note status bar at bottom), but focus then moves to the menu, "RadioButton items"
      */
      package SwingMenuTests;

      import javax.swing.UIManager;

      public class IntlMenuApp {
        boolean packFrame = false;

        //Construct the application
        public IntlMenuApp() {
          IntlMenuFrame frame = new IntlMenuFrame();
          //Validate frames that have preset sizes
          //Pack frames that have useful preferred size info, e.g. from their layout
          if (packFrame)
            frame.pack();
          else
            frame.validate();
          frame.setVisible(true);
        }

        //Main method
        public static void main(String[] args) {
          try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
          }
          catch(Exception e) {
          }
          new IntlMenuApp();
        }
      }

      =============================
      // FILE: /SwingMenuTests/IntlMenuFrame.java
      package SwingMenuTests;

      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;

      public class IntlMenuFrame extends JFrame {
        BorderLayout borderLayout1 = new BorderLayout();
        JMenuBar intlMenuBar1 = new JMenuBar();
        JMenu stdMenu = new JMenu();
        JMenuItem intlMenuItem1 = new JMenuItem();
        JMenuItem intlMenuItem2 = new JMenuItem();
        JMenuItem intlMenuItem3 = new JMenuItem();
        JMenu rbMenu = new JMenu();
        JRadioButtonMenuItem intlRadioButtonMenuItem1 = new JRadioButtonMenuItem();
        JRadioButtonMenuItem intlRadioButtonMenuItem2 = new JRadioButtonMenuItem();
        JRadioButtonMenuItem intlRadioButtonMenuItem3 = new JRadioButtonMenuItem();
        JMenu cbMenu = new JMenu();
        JCheckBoxMenuItem intlCheckBoxMenuItem1 = new JCheckBoxMenuItem();
        JCheckBoxMenuItem intlCheckBoxMenuItem2 = new JCheckBoxMenuItem();
        JCheckBoxMenuItem intlCheckBoxMenuItem3 = new JCheckBoxMenuItem();
        JRadioButtonMenuItem intlRadioButtonMenuItem4 = new JRadioButtonMenuItem();
        JRadioButtonMenuItem intlRadioButtonMenuItem5 = new JRadioButtonMenuItem();
        JRadioButtonMenuItem intlRadioButtonMenuItem6 = new JRadioButtonMenuItem();
        JMenu fileMenu = new JMenu();
        JMenuItem intlMenuItem4 = new JMenuItem();
        ButtonGroup intlMenuGroup1 = new ButtonGroup();
        ButtonGroup intlMenuGroup2 = new ButtonGroup();
        JLabel jdbStatusLabel1 = new JLabel();
        JPanel jPanel1 = new JPanel();
        JLabel jLabel1 = new JLabel();
        JPopupMenu jPopupMenu1 = new JPopupMenu();
        JMenu popupChecks = new JMenu();
        JCheckBoxMenuItem popupCheckBoxMenuItem1 = new JCheckBoxMenuItem();
        JCheckBoxMenuItem popupCheckBoxMenuItem2 = new JCheckBoxMenuItem();
        JCheckBoxMenuItem popupCheckBoxMenuItem3 = new JCheckBoxMenuItem();
        JMenu popupButtons = new JMenu();
        JRadioButtonMenuItem popupRadioButtonMenuItem1 = new JRadioButtonMenuItem();
        JRadioButtonMenuItem popupRadioButtonMenuItem2 = new JRadioButtonMenuItem();
        GridBagLayout gridBagLayout1 = new GridBagLayout();
        ButtonGroup popupGroup = new ButtonGroup();
      //Construct the frame
        public IntlMenuFrame() {
          enableEvents(AWTEvent.WINDOW_EVENT_MASK);
          try {
            jbInit();
          }
          catch(Exception e) {
            e.printStackTrace();
          }
        }

        //Component initialization
        private void jbInit() throws Exception {
          this.getContentPane().setLayout(borderLayout1);
          this.getContentPane().setBackground(new Color(121, 227, 242));
          this.setSize(new Dimension(500, 250));
          this.setTitle("Frame Title");
          stdMenu.setText("Standard menu items");
          stdMenu.setMnemonic('m');
          intlMenuItem1.setText("Derc");
          intlMenuItem1.setMnemonic('D');
          intlMenuItem1.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(ActionEvent e) {
              intlMenuItem1_actionPerformed(e);
            }
          });
          intlMenuItem2.setText("Rick");
          intlMenuItem2.setMnemonic('R');
          intlMenuItem2.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(ActionEvent e) {
              intlMenuItem2_actionPerformed(e);
            }
          });
          intlMenuItem3.setText("Wendy");
          intlMenuItem3.setMnemonic('W');
          intlMenuItem3.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(ActionEvent e) {
              intlMenuItem3_actionPerformed(e);
            }
          });
          rbMenu.setText("RadioButton items");
          rbMenu.setMnemonic('R');
          intlRadioButtonMenuItem1.setText("Pop");
          intlRadioButtonMenuItem1.setMnemonic('P');
          intlRadioButtonMenuItem2.setText("Crackle");
          intlRadioButtonMenuItem2.setMnemonic('C');
          intlRadioButtonMenuItem3.setText("Snap");
          intlRadioButtonMenuItem3.setMnemonic('p');
          cbMenu.setText("CheckBox items");
          cbMenu.setMnemonic('C');
          intlCheckBoxMenuItem1.setText("DataStore");
          intlCheckBoxMenuItem1.setMnemonic('S');
          intlCheckBoxMenuItem2.setText("DataExpress");
          intlCheckBoxMenuItem2.setMnemonic('E');
          intlCheckBoxMenuItem3.setText("dbSwing");
          intlCheckBoxMenuItem3.setMnemonic('d');
          intlRadioButtonMenuItem4.setText("Standard");
          intlRadioButtonMenuItem4.setMnemonic('S');
          intlRadioButtonMenuItem5.setText("Pro");
          intlRadioButtonMenuItem5.setMnemonic('P');
          intlRadioButtonMenuItem6.setText("Enterprise");
          intlRadioButtonMenuItem6.setMnemonic('p');
          fileMenu.setText("File");
          fileMenu.setMnemonic('F');
          intlMenuItem4.setText("Exit");
          intlMenuItem4.setMnemonic('x');
          intlMenuItem4.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(ActionEvent e) {
              intlMenuItem4_actionPerformed(e);
            }
          });

          jdbStatusLabel1.setOpaque(true);
          jPanel1.setOpaque(false);
          jPanel1.setLayout(gridBagLayout1);
          jLabel1.setBackground(Color.white);
          jLabel1.setOpaque(true);
          jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
          jLabel1.setHorizontalTextPosition(SwingConstants.LEFT);

          jLabel1.setText("Right-click me for a pop-up menu");
          jLabel1.addMouseListener(new java.awt.event.MouseAdapter() {

            public void mouseReleased(MouseEvent e) {
              jLabel1_mouseReleased(e);
            }
          });
          popupChecks.setText("Check boxes");
          popupChecks.setMnemonic('C');
          popupCheckBoxMenuItem3.setText("Check");
          popupCheckBoxMenuItem3.setMnemonic('k');
          popupCheckBoxMenuItem2.setText("Cheque");
          popupCheckBoxMenuItem2.setMnemonic('q');
          popupCheckBoxMenuItem1.setText("Czech");
          popupCheckBoxMenuItem1.setMnemonic('z');
          popupButtons.setText("Radio buttons");
          popupButtons.setMnemonic('R');
          popupRadioButtonMenuItem1.setText("Button");
          popupRadioButtonMenuItem1.setMnemonic('B');
          popupRadioButtonMenuItem2.setText("Buttin\'");
          popupRadioButtonMenuItem2.setMnemonic('B');
          jPopupMenu1.setInvoker(jLabel1);
          intlMenuGroup1.add(intlRadioButtonMenuItem1);
          intlMenuGroup1.add(intlRadioButtonMenuItem2);
          intlMenuGroup1.add(intlRadioButtonMenuItem3);
          intlMenuGroup2.add(intlRadioButtonMenuItem4);
          intlMenuGroup2.add(intlRadioButtonMenuItem5);
          intlMenuGroup2.add(intlRadioButtonMenuItem6);
          popupGroup.add(popupRadioButtonMenuItem1);
          popupGroup.add(popupRadioButtonMenuItem2);

          this.getContentPane().add(intlMenuBar1, BorderLayout.NORTH);
          this.getContentPane().add(jdbStatusLabel1, BorderLayout.SOUTH);
          this.getContentPane().add(jPanel1, BorderLayout.CENTER);
          jPanel1.add(jLabel1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
                  ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 20, 10));
          intlMenuBar1.add(fileMenu);
          intlMenuBar1.add(stdMenu);
          intlMenuBar1.add(rbMenu);
          intlMenuBar1.add(cbMenu);
          stdMenu.add(intlMenuItem1);
          stdMenu.add(intlMenuItem2);
          stdMenu.add(intlMenuItem3);
          rbMenu.add(intlRadioButtonMenuItem3);
          rbMenu.add(intlRadioButtonMenuItem2);
          rbMenu.add(intlRadioButtonMenuItem1);
          rbMenu.addSeparator();
          rbMenu.add(intlRadioButtonMenuItem6);
          rbMenu.add(intlRadioButtonMenuItem5);
          rbMenu.add(intlRadioButtonMenuItem4);
          cbMenu.add(intlCheckBoxMenuItem3);
          cbMenu.add(intlCheckBoxMenuItem2);
          cbMenu.add(intlCheckBoxMenuItem1);
          fileMenu.add(intlMenuItem4);
          jPopupMenu1.add(popupChecks);
          jPopupMenu1.add(popupButtons);
          popupChecks.add(popupCheckBoxMenuItem3);
          popupChecks.add(popupCheckBoxMenuItem2);
          popupChecks.add(popupCheckBoxMenuItem1);
          popupButtons.add(popupRadioButtonMenuItem1);
          popupButtons.add(popupRadioButtonMenuItem2);
      }

        //Overriden so we can exit on System Close
        protected void processWindowEvent(WindowEvent e) {
          super.processWindowEvent(e);
          if(e.getID() == WindowEvent.WINDOW_CLOSING) {
            System.exit(0);
          }
        }

        void intlMenuItem4_actionPerformed(ActionEvent e) {
          System.exit(0);
        }

        void intlMenuItem1_actionPerformed(ActionEvent e) {
          jdbStatusLabel1.setText("Derc");
        }

        void intlMenuItem2_actionPerformed(ActionEvent e) {
          jdbStatusLabel1.setText("Rick");
        }

        void intlMenuItem3_actionPerformed(ActionEvent e) {
          jdbStatusLabel1.setText("Wendy");
        }

        void jLabel1_mouseReleased(MouseEvent e) {
          if (e.isPopupTrigger()) {
      // How to show popup in the right place without using a deprecated method?
            jPopupMenu1.show(jLabel1, e.getX(), e.getY());
          }
        }
      }
      (Review ID: 57832)
      ======================================================================

            gsaab Georges Saab
            clucasius Carlos Lucasius (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: