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

[macosx] Support duplicate mnemonics in menus - fails for JRadioButtonMenuItem

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version " 1.7.0_07 "
      Java(TM) SE Runtime Environment (build 1.7.0_07-b10)
      Java HotSpot(TM) 64-Bit Server VM (build 23.3-b01, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Mac OS X Mountain Lion at the moment: Darwin Macintosh.local 12.2.0 Darwin Kernel Version 12.2.0: Sat Aug 25 00:48:52 PDT 2012; root:xnu-2050.18.24~1/RELEASE_X86_64 x86_64

      Probably all OS's using BasicPopupMenuUI

      A DESCRIPTION OF THE PROBLEM :
        Bug fixes 4515762 and 4670831 did not correctly fix support for duplicate mnemonics in JPopupMenu. I have a JPopupMenu with the same mnemonic character specified for two JRadioButtonMenuItems. Posting the menu and pressing the mnemonic character only highlights the first such menu item, never the second one.

      By code inspection, the error is in the logic that BasicPopupMenuUI.BasicMenuKeyListener uses to reject a menu item that is already highlighted.

      It checks if AbstractButton.isSelected(), when it should check if the JMenuItem is the last item in the MenuSelectionManager selected path.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create and show a JPopupMenu with the same mnemonic character on two JRadioButtonMenuItems. Ensure that those 2 JRadioButtonMenuItems are in their unselected states. (Formally, that AbstractButton.isSelected() returns false). Press the mnemonic character (possibly with the OS-specific modifier such as Alt). Observe that the first matching menu item becomes highlighted. Press the mnemonic character again.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      After pressing the mnemonic character the second time, the second matching menu item should become highlighted.
      ACTUAL -
      After pressing the mnemonic character the second time, the first matching menu item remains highlighted.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      CUSTOMER SUBMITTED WORKAROUND :
      Whenever you create a JPopupMenu or reinstall its UI, iterate the result of getMenuKeyListeners() and remove any listener that has BasicMenuItemUI as its enclosing class (in other words, remove the listener of private class BasicMenuItemUI.BasicMenuKeyListener).

      Then, add a corrected menu key listener.

      I corrected BasicMenuItemUI.BasicMenuKeyListener by replace the following line:

                     if (item.isArmed() || item.isSelected()) {

      with this block of code:

                      final MenuElement[] selPath = manager.getSelectedPath();
                      final boolean pathToItemIsSelected = selPath.length > 0 && selPath[selPath.length - 1] == item;
                      if (item.isArmed() || pathToItemIsSelected ) {

            alexp Alexander Potochkin (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: