Example usage for javax.swing JMenu JMenu

List of usage examples for javax.swing JMenu JMenu

Introduction

In this page you can find the example usage for javax.swing JMenu JMenu.

Prototype

public JMenu(String s, boolean b) 

Source Link

Document

Constructs a new JMenu with the supplied string as its text and specified as a tear-off menu or not.

Usage

From source file:Main.java

public static void main(final String args[]) {
    JFrame frame = new JFrame("MenuSample Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JMenuBar menuBar = new JMenuBar();

    // File Menu, F - Mnemonic
    JMenu fileMenu = new JMenu("File", false);
    fileMenu.setMnemonic(KeyEvent.VK_F);
    menuBar.add(fileMenu);//from   w  w  w . ja  v  a 2s.c  om

    // File->New, N - Mnemonic
    JMenuItem newMenuItem = new JMenuItem("New", KeyEvent.VK_N);
    fileMenu.add(newMenuItem);

    JCheckBoxMenuItem caseMenuItem = new JCheckBoxMenuItem("Case Sensitive");
    caseMenuItem.setMnemonic(KeyEvent.VK_C);
    fileMenu.add(caseMenuItem);

    frame.setJMenuBar(menuBar);
    frame.setSize(350, 250);
    frame.setVisible(true);
}

From source file:org.jfree.chart.demo.SuperDemo.java

private JMenuBar createMenuBar() {
    JMenuBar jmenubar = new JMenuBar();
    JMenu jmenu = new JMenu("File", true);
    jmenu.setMnemonic('F');
    JMenuItem jmenuitem = new JMenuItem("Export to PDF...", 112);
    jmenuitem.setActionCommand("EXPORT_TO_PDF");
    jmenuitem.addActionListener(this);
    jmenu.add(jmenuitem);/*w  ww .  jav a 2s  .c o m*/
    jmenu.addSeparator();
    JMenuItem jmenuitem1 = new JMenuItem("Exit", 120);
    jmenuitem1.setActionCommand("EXIT");
    jmenuitem1.addActionListener(this);
    jmenu.add(jmenuitem1);
    jmenubar.add(jmenu);
    return jmenubar;
}