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

JPopupMenu doesn't support arrow key navigation or Enter

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.1.1, 1.1.6, 1.2.2
    • client-libs
    • beta
    • generic, x86
    • generic, windows_nt



      Name: clC74495 Date: 02/18/99


      Code to repro at end. Click on "Press me", then try to
      use the arrow keys or enter to dismiss the popup menu.
      (I'm using Swing 1.1.1-beta1)

      This is a pretty nasty limitation that can have implications
      for handicapped users - even if we make showing the JPopupMenu
      keyboard accessible (e.g., via Shift-F10), the menu itself
      isn't accessible at all).

      (Various bugs have been filed against related issues -
      Esc key not working, accelerators not working - but none
      against this per se as far as I can see)

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

      public class PopupMenu extends JPanel
      {
        static public void main(String[] args)
        {
          JFrame frame = new JFrame();
          frame.setContentPane(new PopupMenu());
          frame.pack();
          frame.setSize(400, 400);
          frame.setVisible(true);
        }

        public PopupMenu()
        {
          final JButton test = new JButton("Press me!");
          test.addActionListener(new ActionListener()
          {
            public void actionPerformed(ActionEvent e)
            {
              JPopupMenu popup = new JPopupMenu();
              popup.add("Item 1");
              popup.add("Item 2");
              popup.add("Item 3");
              popup.show(test, 0, 0);
            }
          });

          add(test);
        }
      }
      (Review ID: 54311)
      ======================================================================

      Name: skT88420 Date: 04/21/99


      My JApplet has a JMenuBar. When the JPopupMenu shows out side of the JApplet boundary, the left and right arrow keys do not work properly. It seems that once the JPopupMenu shows outside of JApplet, it is stuck there.

      HTML CODE:
      <APPLET CODE=MixPopupTest.class Width=400 HEIGHT=480></APPLET>

      Here is the source code:

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

      public class MixPopupTest extends JApplet {

         public void init() {

      JMenuBar menubar = new JMenuBar();


      // Create lightweight-enabled menu
              JMenu menu = new JMenu("Lite Menu");

              menu.add("Salad");
              menu.add("Fruit Plate");
              menu.add("Water");
              menubar.add(menu);
               
      // Create lightweight-disabled menu
      for (int i = 0; i < 5; i++ ) {

                 JPopupMenu.setDefaultLightWeightPopupEnabled(false);

      menu = new JMenu("Heavy Menu " + i);
              
      menu.add("Filet Mignon");
      menu.add("Gravy");
      menu.add("Banana Split");
      menu.add("A very very very long item");
             
      menubar.add(menu);
      }
              
              
      box.add(Box.createVerticalStrut(20));
              
      getContentPane().add("Center", box);

      setJMenuBar(menubar);
         }
      }


      java -fullversion: java full version "JDK1.1.5K"

      swing version: 1.1 RELEASE
      ======================================================================

      Name: vi73552 Date: 06/22/99


      Popup menus do not accept keyboard input at all - according to
      the Swing API, up/down arrows should move the highlighted item,
      space bar should select, and so on.

      To reproduce the problem compile the following source code, run
      the application, and click the mouse to bring up the popup.
      Shift + F10 is supposed to bring up the menu as well, but this
      doesn't work, although according to the Swing API it should.


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

      public class PopupBug extends JFrame{
        private JPopupMenu popup;
        public PopupBug(){
          super("Popup");
          init();
        }
        private void init(){
          setPopup();
          addMouseListener(new MouseAdapter(){
            public void mousePressed( MouseEvent e ){
              if(e.isPopupTrigger()){
                popup.show(getThis(),e.getX(),e.getY());
              }
            }
            public void mouseClicked( MouseEvent e ){
              if(e.isPopupTrigger()){
                popup.show(getThis(),e.getX(),e.getY());
              }
            }
            public void mouseReleased( MouseEvent e ){
              if(e.isPopupTrigger()){
                popup.show(getThis(),e.getX(),e.getY());
              }
            }
          });
          setSize(400,400);
          setLocation(450,200);
          setVisible(true);
        }
        private void setPopup(){
          popup = new JPopupMenu();
          JMenuItem item;
          popup.add(item=new JMenuItem("Confirm"));
          item.setMnemonic('C');
          popup.add(item=new JMenuItem("Add"));
          item.setMnemonic('A');
          popup.add(item=new JMenuItem("Delete"));
          item.setMnemonic('D');
          popup.add(item=new JMenuItem("Print"));
          item.setMnemonic('P');
          popup.addSeparator();
          popup.add(item=new JMenuItem("Quit"));
          item.setMnemonic('Q');
        }
        private JFrame getThis(){return this;}
        public static void main(String[] args){
          new PopupBug();
        }
      }

      No errors occurred, it just doesn't work.



      Output of -version = 1.1.7A
      <I have reproduced it under JDK1.2.2 too, Vasya>
      Output of -fullversion = JDK1.1.7A IBM build o117-19981120
        (JIT enabled:javax)

      This was in OS/2 - the problem also occurred in NT
      (Review ID: 84639)
      ======================================================================

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: