title: Swing: How to provide delay on opening menu from menu-bar/submenu
body: <p>I have an application with a vertical menu bar and lots of submenus. My problem is: submenu goes open immediately after entering by mouse over the corresponded label in parent menu/menu bar. But I need one second delay.</p>
  
  <p>Here is one example:</p>
  
  <p><a href="https://i.stack.imgur.com/9hMW3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9hMW3.png" alt="enter image description here"></a></p>
  
  <p>When I move the mouse from start to end point (see arrow) the initially opened menu will be closed after entering of menu "Second".</p>
  
  <p>Same case is for submenu:</p>
  
  <p><a href="https://i.stack.imgur.com/IUyl5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IUyl5.png" alt="enter image description here"></a></p>
  
  <p>In Windows native applications the second case works correctly, so I can move mouse over the subelement without to lost the currently opened submenu.</p>
  
  <p>Have somebody an idea, how can I implement the required delay?</p>
  
  <p>Here is the code example</p>
  
  <pre><code>import java.awt.BorderLayout;
  import java.awt.GridLayout;
  import java.awt.Point;
  
  import javax.swing.JFrame;
  import javax.swing.JMenu;
  import javax.swing.JMenuBar;
  import javax.swing.JScrollPane;
  import javax.swing.JTextArea;
  import javax.swing.UIManager;
  import javax.swing.WindowConstants;
  
  public class MenuTryout {
  
      public static void main(String[] args) throws Exception {
          UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
          final JFrame frm = new JFrame("Menu test");
          final JMenuBar menuBar = new JMenuBar();
          menuBar.setLayout(new GridLayout(15, 1)); // in my application I use a custom layout here
          JMenu m1 = new VerticalMenu("First");
          m1.add("Subelement 1");
          m1.add("Subelement 2");
          m1.add("Subelement 3");
          final JMenu m11 = new JMenu("Submenu");
          m11.add("Subelement 1.1");
          m11.add("Subelement 1.2");
          m11.add("Subelement 1.3");
          m1.add(m11);
          m1.add("Subelement 4");
          m1.add("Subelement 5");
          menuBar.add(m1);
          m1 = new VerticalMenu("Second");
          m1.add("Subelement 1");
          m1.add("Subelement 2");
          m1.add("Subelement 3");
          menuBar.add(m1);
          m1 = new VerticalMenu("Third");
          m1.add("Subelement 1");
          m1.add("Subelement 2");
          m1.add("Subelement 3");
          menuBar.add(m1);
          frm.add(menuBar, BorderLayout.WEST);
          frm.add(new JScrollPane(new JTextArea(20, 80)));
          frm.pack();
          frm.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
          frm.setVisible(true);
      }
  
      private static class VerticalMenu extends JMenu {
          public VerticalMenu(String aText) {
              super(aText);
          }
          @Override
          protected Point getPopupMenuOrigin() {
              return new Point(getWidth() + 5, 0);
          }
      }
  }
  </code></pre>