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

REGRESSION: Heavyweight JPopupMenu doesn't get focus for key commands on Windows

    XMLWordPrintable

Details

    • beta
    • x86
    • windows_nt

    Description

      JDK 1.4.beta b35 This regression was introduced in the focus enhancements work.

      The keyboard acellerators and mnemonics do not work when heavyweight JPopupMenus are used for the JMenu popup portion. JPopupMenu will become heavyweight when the size of the menu exceeds the bounds of the enclosing window. I think the focus may getting lost when a heavyweight window appears.

      To reproduce:

      Run the following application and try to use Alt-f to bring up the File menu. If that doesn't work, use the mouse to open the file menu and try using the arrow keys to navigate to other menus or menu items. If you expand the enclosing window so that it completly contains the menus, the key navigation seems to work.

      Another aspect of this bug is that the focus tends to get lost when the window is opened or expanded and the menu must be clicked in order for it to find the focus again.

      >>>> HeavyWeightBug.java
      /**
       * HeavyWeightBug - Application which tests the menu changes
       */
      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.*;

      public class HeavyWeightBug extends JFrame implements ActionListener {

          public HeavyWeightBug(String title) {
      this.setTitle(title);
      this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      this.setJMenuBar(createMenu());
      this.pack();
          }

          /**
           * Creates the menu for the application
           */
          private JMenuBar createMenu() {
      //Menu 1
      JMenu menu1 = createFileMenu();

      //Menu2
      JMenu menu2 = new JMenu("Options and other Stuff");
      menu2.setMnemonic('O');
      JCheckBoxMenuItem checkItem = new JCheckBoxMenuItem("Check this out!");
      checkItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,
                      ActionEvent.ALT_MASK + ActionEvent.SHIFT_MASK + ActionEvent.CTRL_MASK));
      checkItem.setEnabled(false);
      checkItem.setMnemonic('C');

      JRadioButtonMenuItem radioItem;
      radioItem = new JRadioButtonMenuItem("Video killed the radio star!");
      radioItem.setMnemonic('V');

      // The mnemonic for the next item is the same as the menu
      // to test the common mnemonic bug 4213634
      JMenuItem normItem = createMenuItem("Normal", 'O');
      JMenuItem iconItem = createMenuItem("Iconize it!", 'I');
      iconItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE,
      ActionEvent.CTRL_MASK));
      menu2.add(checkItem);
      menu2.add(radioItem);
      menu2.add(normItem);
      menu2.add(new JSeparator());
      menu2.add(iconItem);

      //SubMenu
      JMenu submenu = new JMenu("SubWay!");
      submenu.setMnemonic('S');

      JMenuItem item1 = createMenuItem("First SubMenuItem",'F');
      JMenuItem item2 = createMenuItem("Second SubMenuItem", 'S');
      JMenuItem item3 = createMenuItem("Third SubMenuItem", 'T');
          
      submenu.add(item1);
      submenu.add(new JSeparator());
      submenu.add(item2);
      submenu.add(item3);

      menu2.add(submenu);

      JMenuBar menubar = new JMenuBar();
      menubar.add(menu1);
      menubar.add(menu2);

      return menubar;
          }

          private JMenu createFileMenu() {
      JMenu menu1 = new JMenu("File");
      menu1.setMnemonic('F');
      JMenuItem openItem = createMenuItem("Open", 'O');
      openItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE,
      ActionEvent.ALT_MASK+ ActionEvent.CTRL_MASK ));

      JMenuItem newItem = createMenuItem("New Stuff and other stuff too", 'N');
           newItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE,
      ActionEvent.ALT_MASK + ActionEvent.CTRL_MASK));

      JMenuItem quitItem = createMenuItem("Quit", 'Q');
      quitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.ALT_MASK));
      quitItem.setActionCommand("exit");

      menu1.add(openItem);
      menu1.add(newItem);
      menu1.add(new JSeparator());
      menu1.add(quitItem);

      return menu1;
          }

          /**
           * Creates and returns the menu item.
           */
          private JMenuItem createMenuItem(String name, char mnemonic) {
      JMenuItem menuItem = new JMenuItem(name, mnemonic);
      menuItem.addActionListener(this);

      return menuItem;
          }

          public void actionPerformed(ActionEvent e) {
      Object source = e.getSource();
      if (source instanceof JMenuItem) {
      JMenuItem menuItem = (JMenuItem)source;
      if(e.getActionCommand().equals("exit")) {
      this.dispose();
      System.exit(0);
      } else {
      System.out.println("Menu Action: " + menuItem.getText());
      }
      }
          }

          public static void main(String[] args) {
      (new HeavyWeightBug("TestFrame") ).show();
          }
      }
      <<<< HeavyWeightBug.java


      mark.davidson@Eng 2000-11-08

      Attachments

        Activity

          People

            mdavidsosunw Mark Davidson (Inactive)
            mdavidsosunw Mark Davidson (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: