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

Arrow key traversal in JMenu broken after removeAll() from PopupMenuListener

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 1.4.0
    • 1.3.0
    • client-libs
    • beta2
    • x86
    • windows_2000



      Name: boT120536 Date: 05/13/2001


      java version "1.3.0_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0_01)
      Java HotSpot(TM) Client VM (build 1.3.0_01, mixed mode)

      I have a JMenu which has dynamic contents. I am attaching a PopupMenuListener
      to the JMenu, and on popupMenuWillBecomeVisible(), I am removing all of the
      menu items and rebuilding the menu. This works, but after I've called removeAll
      (), I can no longer use the arrow keys to traverse the menu properly if I call
      the menu from its mnemonic. Another strange thing is that if I get to the menu
      from another menu (i.e. hitting another menu's mnemonic and then arrowing to
      change menus), it will work. Also, if I activate the menu with the mouse, then
      arrow keys will work. The following class demonstrates the problem:

      ===============

      import javax.swing.*;
      import javax.swing.event.*;

      import java.awt.*;
      import java.awt.event.*;

      public class MenuRebuildTest extends JFrame implements PopupMenuListener {
      public JMenu menu;
      public int num = 0;

      public MenuRebuildTest() {
      super("MenuRebuildTest");

      JMenuBar bar = new JMenuBar();



      menu = new JMenu("Menu");
      menu.setMnemonic(KeyEvent.VK_M);
      menu.getPopupMenu().addPopupMenuListener(this);
      bar.add(menu);

      JMenu menu2 = new JMenu("Options");
      menu2.setMnemonic(KeyEvent.VK_O);
      menu2.add(new JMenuItem("None"));
      bar.add(menu2);

      setJMenuBar(bar);

      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setSize(300, 200);
      }

      public static void main(String[] args) {
      new MenuRebuildTest().show();
      }

      public void rebuildMenu() {
      num++;
      menu.removeAll();
      for (int i = 0; i < num; i++) {
      menu.add(new JMenuItem("Item #" + i));
      }
      }

      public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
      rebuildMenu();
      }

      public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {}
      public void popupMenuCanceled(PopupMenuEvent e) {}
      }

      ===============

      Steps to recreate:

        1. Hit Alt-M to bring up the first menu
        2. You CAN arrow-down to Item #0
        3. Hit ESC to dismiss the menu
        4. Hit Alt-M to bring up the first menu again
        5. You CANNOT arrow-down to the new menu items
        6. Hit ESC to dismiss the menu
        7. Hit Alt-O to bring up the second menu
        8. Hit left-arrow to go back to the first menu
        9. You CAN arrow up and down
       10. Hit ESC to dismiss the menu
       11. Open the menu by clicking with the mouse, but do not select an item
       12. You CAN arrow up and down

      This has quite a serious effect on the accessability and usability of our menus.

      (Just as an aside, this program will not work at all in the merlin beta, the
      menu mnemonics will not open the menu at all!)
      (Review ID: 123735)
      ======================================================================

            mdavidsosunw Mark Davidson (Inactive)
            bonealsunw Bret O'neal (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: