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

Delay should be respected before hiding a JMenu

    XMLWordPrintable

    Details

      Description

      A DESCRIPTION OF THE REQUEST :
      JMenu's delay option is only respected before a JMenu pops in. It's not respected when the menu pops out (when it hides).

      1. Run the attached example.
      2. Click on the root menu.
      3. Move mouse pointer over menu1.
      4. Wait 3 seconds until the submenu pops in.
      5. Move mouse pointer over menu2. Notice that menu1 hides immediately.

      Javadoc might be misleading in this point. It says "before submenus are popped up or down". "Popping down" could be understood as "hiding", but it rather has the meaning of "submenu is rendered below his parent menu".

      JUSTIFICATION :
      When you have a menu delay configured in your desktop environment, it's likely that the delay is used before opening a new submenu and before hiding the previously open submenu. Try it in your desktop start menu or the menubar of a non-Java application. Therefore many users will expect and miss this feature in Swing.

      I.e. here: http://forum.java.sun.com/thread.jspa?forumID=257&threadID=292164
      Or here: http://forum.java.sun.com/thread.jspa?forumID=57&threadID=667694

      Having large menus (long item names, several level of depth) without "hide delay" can become frustrating, because you have to aim carefully when moving mouse pointer.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      When moving mouse over menu2, menu1 should remain open for 3 seconds, after that time menu1 should hide and instantly (with no further delay) menu2 should appear.

      ACTUAL -
      menu1 closes immediately. There is no menu shown for 3 seconds until menu2 appears.

      ---------- BEGIN SOURCE ----------
      import java.awt.FlowLayout;

      import javax.swing.JFrame;
      import javax.swing.JLabel;
      import javax.swing.JMenu;
      import javax.swing.JMenuBar;
      import javax.swing.JMenuItem;

      class JMenuDelay extends JFrame {

      final static int DELAY_MS = 3000;

      JMenuDelay() {
      // menu 1 & 2
      JMenu menu1 = new JMenu("menu1");
      JMenu menu2 = new JMenu("menu2");
      menu1.setDelay(DELAY_MS);
      menu2.setDelay(DELAY_MS);
      menu1.add(new JMenuItem("foo"));
      menu2.add(new JMenuItem("bar"));

      // root menu
      JMenu rootMenu = new JMenu("rootMenu");
      rootMenu.add(menu1);
      rootMenu.add(menu2);

      // menubar
      JMenuBar menuBar = new JMenuBar();
      menuBar.add(rootMenu);
      add(menuBar);

      // build frame
      add(new JLabel("delay is " + DELAY_MS + " ms"));
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setLayout(new FlowLayout());
      setSize(300, 300);
      setLocationByPlatform(true);
      setVisible(true);
      }

      public static void main(String[] args) {
      new JMenuDelay();
      }
      }

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

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Imported:
              Indexed: