Java Swing Tutorial - Java JMenu.getDelay()








Syntax

JMenu.getDelay() has the following syntax.

public int getDelay()

Example

In the following code shows how to use JMenu.getDelay() method.

import java.awt.Component;
import java.awt.ComponentOrientation;
/*w ww .  ja va  2 s .co m*/
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JSeparator;

public class Main extends JFrame {
  public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JMenuBar bar = new JMenuBar();
    JMenu menu = new JMenu("File");
    ComponentOrientation ori = ComponentOrientation.LEFT_TO_RIGHT;
    
    menu.applyComponentOrientation(ori);
    bar.add(menu);

    menu.add(new JMenuItem("Close"));
    menu.add(new JSeparator()); // SEPARATOR
    menu.add(new JMenuItem("Exit"));
    
    setJMenuBar(bar);
    add(new JLabel("A placeholder"));

    pack();
    setSize(300, 300);
    setVisible(true);
    
    System.out.println(menu.getDelay());

  }

  public static void main(String arg[]) {
    new Main();
  }
}