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

Escape Key causes JMenu Selection to Disappear

XMLWordPrintable

    • b03
    • x86
    • windows_xp
    • Verified

      FULL PRODUCT VERSION :
      java version "1.5.0_06"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
      Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Windows XP PRO Ver 2002 SP2

      A DESCRIPTION OF THE PROBLEM :
      If a JMenu is inside a menu that is attached to the JMenuBar, and it has A SubMenu attached to it (showing the black arrow to the right ">"), its text can be hidden by hovering over it and pressing the escape key.

       The problem is that the selection for the JMenu item is being removed due to whatever action listener the VK_ESCAPE KeyEvent is running, but the foreground text of the JMenu is not being reset back to black.



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Run the code
      2. Click on "Menu" on the MenuBar
      3. Hover over "Menu With Arrow" inside the menu, you should see "Popup Menu Item" in a subMenu.
      4. Keep "Popup Menu Item" UNSELECTED (your mouse has to be over "Menu With Arrow").
      5. Hit "ESCAPE KEY".
      6. Watch Selection on "Menu WIth Arrow" menu disappear, leaving the text foreground as white.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The selection should remain ON, allowing us to see the WHITE text. Because the mouse is STILL over the JMenu, the selection should not disappear in this case.
      ACTUAL -
      The selection disappears, and because the foreground text is still white, we are unable to read the JMenu text.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.Dimension;
      import javax.swing.JFrame;
      import javax.swing.JMenu;
      import javax.swing.JMenuBar;
      import javax.swing.JMenuItem;
      import javax.swing.UIManager;
       
      public class BrokenEscapeTest extends JFrame
      {
      private JMenuBar mainMenuBar;
      private JMenu menuBarMenu;
      private JMenu menuWithArrow;
      private JMenuItem popupMenuItem;
      private JMenuItem menuItem;

      public BrokenEscapeTest()
      {
      this.setSize(new Dimension(400,300));
      this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
      this.setJMenuBar(getMainMenuBar());
      this.setVisible(true);
      }

      private JMenuBar getMainMenuBar()
      {
      if(mainMenuBar == null)
      {
      mainMenuBar = new JMenuBar();
      mainMenuBar.add(getMenuBarMenu());
      }
      return mainMenuBar;
      }

      private JMenu getMenuBarMenu()
      {
      if(menuBarMenu == null)
      {
      menuBarMenu = new JMenu("Menu");
      menuBarMenu.add(getMenuWithArrow());
      menuBarMenu.add(getMenuItem());
      }
      return menuBarMenu;
      }

      private JMenu getMenuWithArrow()
      {
      if(menuWithArrow == null)
      {
      menuWithArrow = new JMenu("Menu With Arrow");
      menuWithArrow.add(getPopupMenuItem());
      }
      return menuWithArrow;
      }

      private JMenuItem getPopupMenuItem()
      {
      if(popupMenuItem == null)
      {
      popupMenuItem = new JMenuItem("Popup Menu Item");
      }
      return popupMenuItem;
      }

      private JMenuItem getMenuItem()
      {
      if(menuItem == null)
      {
      menuItem = new JMenuItem("Extra Item");
      }
      return menuItem;
      }

      public static void main(String args[])
      {
      try
      {
      UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
      }
      catch(Exception ex)
      {
      ex.printStackTrace();
      }
       
      new BrokenEscapeTest();
      }
      }

      ---------- END SOURCE ----------

            alexp Alexander Potochkin (Inactive)
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: