Example usage for java.awt.event KeyEvent VK_N

List of usage examples for java.awt.event KeyEvent VK_N

Introduction

In this page you can find the example usage for java.awt.event KeyEvent VK_N.

Prototype

int VK_N

To view the source code for java.awt.event KeyEvent VK_N.

Click Source Link

Document

Constant for the "N" key.

Usage

From source file:be.fedict.eid.tsl.tool.TslTool.java

private void initNewMenu(JMenu fileMenu) {
    JMenu newMenu = new JMenu("New");
    newMenu.setMnemonic(KeyEvent.VK_N);
    fileMenu.add(newMenu);//from   w w w.j av  a  2  s .c  o  m

    JMenu belgiumMenu = new JMenu("Belgium");
    newMenu.add(belgiumMenu);

    JMenu _2010BelgiumMenu = new JMenu("2010");
    belgiumMenu.add(_2010BelgiumMenu);

    JMenuItem _2010_T1_BelgiumMenuItem = addActionMenuItem("Trimester 1", KeyEvent.VK_1, "TSL-BE-2010-T1",
            _2010BelgiumMenu, true);
    _2010BelgiumMenu.add(_2010_T1_BelgiumMenuItem);

    JMenuItem _2010_T2_BelgiumMenuItem = addActionMenuItem("Trimester 2", KeyEvent.VK_2, "TSL-BE-2010-T2",
            _2010BelgiumMenu, true);
    _2010BelgiumMenu.add(_2010_T2_BelgiumMenuItem);

    JMenuItem _2010_T3_BelgiumMenuItem = addActionMenuItem("Trimester 3", KeyEvent.VK_3, "TSL-BE-2010-T3",
            _2010BelgiumMenu, true);
    _2010BelgiumMenu.add(_2010_T3_BelgiumMenuItem);

    JMenu _2011BelgiumMenu = new JMenu("2011");
    belgiumMenu.add(_2011BelgiumMenu);

    addActionMenuItem("Trimester 1", KeyEvent.VK_1, "TSL-BE-2011-T1", _2011BelgiumMenu, true);
    addActionMenuItem("Trimester 2", KeyEvent.VK_2, "TSL-BE-2011-T2", _2011BelgiumMenu, true);
    addActionMenuItem("Trimester 3", KeyEvent.VK_3, "TSL-BE-2011-T3", _2011BelgiumMenu, true);

    JMenu _2012BelgiumMenu = new JMenu("2012");
    belgiumMenu.add(_2012BelgiumMenu);

    addActionMenuItem("Trimester 1", KeyEvent.VK_1, "TSL-BE-2012-T1", _2012BelgiumMenu, true);
    addActionMenuItem("Trimester 2", KeyEvent.VK_2, "TSL-BE-2012-T2", _2012BelgiumMenu, true);
    addActionMenuItem("Trimester 3", KeyEvent.VK_3, "TSL-BE-2012-T3", _2012BelgiumMenu, true);

    JMenu _2013BelgiumMenu = new JMenu("2013");
    belgiumMenu.add(_2013BelgiumMenu);

    addActionMenuItem("Trimester 1", KeyEvent.VK_1, "TSL-BE-2013-T1", _2013BelgiumMenu, true);
    addActionMenuItem("Trimester 2", KeyEvent.VK_2, "TSL-BE-2013-T2", _2013BelgiumMenu, true);
    addActionMenuItem("Trimester 3", KeyEvent.VK_3, "TSL-BE-2013-T3", _2013BelgiumMenu, true);

    JMenu _2014BelgiumMenu = new JMenu("2014");
    belgiumMenu.add(_2014BelgiumMenu);

    addActionMenuItem("Trimester 1", KeyEvent.VK_1, "TSL-BE-2014-T1", _2014BelgiumMenu, true);
    addActionMenuItem("Trimester 2", KeyEvent.VK_1, "TSL-BE-2014-T2", _2014BelgiumMenu, true);
    addActionMenuItem("Trimester 3", KeyEvent.VK_1, "TSL-BE-2014-T3", _2014BelgiumMenu, true);

    JMenu _2015BelgiumMenu = new JMenu("2015");
    belgiumMenu.add(_2015BelgiumMenu);

    addActionMenuItem("Trimester 1", KeyEvent.VK_1, "TSL-BE-2015-T1", _2015BelgiumMenu, true);
    addActionMenuItem("Trimester 2", KeyEvent.VK_1, "TSL-BE-2015-T2", _2015BelgiumMenu, true);
    addActionMenuItem("Trimester 3", KeyEvent.VK_1, "TSL-BE-2015-T3", _2015BelgiumMenu, true);

}

From source file:components.MenuLookDemo.java

public JMenuBar createMenuBar() {
    JMenuBar menuBar;/*w  ww .j a  v  a2 s .  c  o  m*/
    JMenu menu, submenu;
    JMenuItem menuItem;
    JRadioButtonMenuItem rbMenuItem;
    JCheckBoxMenuItem cbMenuItem;

    //Create the menu bar.
    menuBar = new JMenuBar();

    //Build the first menu.
    menu = new JMenu("A Menu");
    menu.setMnemonic(KeyEvent.VK_A);
    menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items");
    menuBar.add(menu);

    //a group of JMenuItems
    menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T);
    //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything");
    menu.add(menuItem);

    ImageIcon icon = createImageIcon("images/middle.gif");
    menuItem = new JMenuItem("Both text and icon", icon);
    menuItem.setMnemonic(KeyEvent.VK_B);
    menu.add(menuItem);

    menuItem = new JMenuItem(icon);
    menuItem.setMnemonic(KeyEvent.VK_D);
    menu.add(menuItem);

    //a group of radio button menu items
    menu.addSeparator();
    ButtonGroup group = new ButtonGroup();

    rbMenuItem = new JRadioButtonMenuItem("A radio button menu item");
    rbMenuItem.setSelected(true);
    rbMenuItem.setMnemonic(KeyEvent.VK_R);
    group.add(rbMenuItem);
    menu.add(rbMenuItem);

    rbMenuItem = new JRadioButtonMenuItem("Another one");
    rbMenuItem.setMnemonic(KeyEvent.VK_O);
    group.add(rbMenuItem);
    menu.add(rbMenuItem);

    //a group of check box menu items
    menu.addSeparator();
    cbMenuItem = new JCheckBoxMenuItem("A check box menu item");
    cbMenuItem.setMnemonic(KeyEvent.VK_C);
    menu.add(cbMenuItem);

    cbMenuItem = new JCheckBoxMenuItem("Another one");
    cbMenuItem.setMnemonic(KeyEvent.VK_H);
    menu.add(cbMenuItem);

    //a submenu
    menu.addSeparator();
    submenu = new JMenu("A submenu");
    submenu.setMnemonic(KeyEvent.VK_S);

    menuItem = new JMenuItem("An item in the submenu");
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK));
    submenu.add(menuItem);

    menuItem = new JMenuItem("Another item");
    submenu.add(menuItem);
    menu.add(submenu);

    //Build second menu in the menu bar.
    menu = new JMenu("Another Menu");
    menu.setMnemonic(KeyEvent.VK_N);
    menu.getAccessibleContext().setAccessibleDescription("This menu does nothing");
    menuBar.add(menu);

    return menuBar;
}

From source file:MenuLookDemo.java

public JMenuBar createMenuBar() {
    JMenuBar menuBar;// w ww  .j  a  va 2s  .c  om
    JMenu menu, submenu;
    JMenuItem menuItem;
    JRadioButtonMenuItem rbMenuItem;
    JCheckBoxMenuItem cbMenuItem;

    // Create the menu bar.
    menuBar = new JMenuBar();

    // Build the first menu.
    menu = new JMenu("A Menu");
    menu.setMnemonic(KeyEvent.VK_A);
    menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items");
    menuBar.add(menu);

    // a group of JMenuItems
    menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T);
    // menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything");
    menu.add(menuItem);

    ImageIcon icon = createImageIcon("images/middle.gif");
    menuItem = new JMenuItem("Both text and icon", icon);
    menuItem.setMnemonic(KeyEvent.VK_B);
    menu.add(menuItem);

    menuItem = new JMenuItem(icon);
    menuItem.setMnemonic(KeyEvent.VK_D);
    menu.add(menuItem);

    // a group of radio button menu items
    menu.addSeparator();
    ButtonGroup group = new ButtonGroup();

    rbMenuItem = new JRadioButtonMenuItem("A radio button menu item");
    rbMenuItem.setSelected(true);
    rbMenuItem.setMnemonic(KeyEvent.VK_R);
    group.add(rbMenuItem);
    menu.add(rbMenuItem);

    rbMenuItem = new JRadioButtonMenuItem("Another one");
    rbMenuItem.setMnemonic(KeyEvent.VK_O);
    group.add(rbMenuItem);
    menu.add(rbMenuItem);

    // a group of check box menu items
    menu.addSeparator();
    cbMenuItem = new JCheckBoxMenuItem("A check box menu item");
    cbMenuItem.setMnemonic(KeyEvent.VK_C);
    menu.add(cbMenuItem);

    cbMenuItem = new JCheckBoxMenuItem("Another one");
    cbMenuItem.setMnemonic(KeyEvent.VK_H);
    menu.add(cbMenuItem);

    // a submenu
    menu.addSeparator();
    submenu = new JMenu("A submenu");
    submenu.setMnemonic(KeyEvent.VK_S);

    menuItem = new JMenuItem("An item in the submenu");
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK));
    submenu.add(menuItem);

    menuItem = new JMenuItem("Another item");
    submenu.add(menuItem);
    menu.add(submenu);

    // Build second menu in the menu bar.
    menu = new JMenu("Another Menu");
    menu.setMnemonic(KeyEvent.VK_N);
    menu.getAccessibleContext().setAccessibleDescription("This menu does nothing");
    menuBar.add(menu);

    return menuBar;
}

From source file:ee.ioc.cs.vsle.editor.Editor.java

/**
 * Build menu.// w w w  .ja  v a2s. com
 */
public void makeMenu() {
    JMenuItem menuItem;

    JMenu menu;
    JMenu submenu;

    menuBar = new JMenuBar();
    setJMenuBar(menuBar);
    menu = new JMenu(Menu.MENU_FILE);
    menu.setMnemonic(KeyEvent.VK_F);
    menuItem = new JMenuItem(Menu.NEW_SCHEME, KeyEvent.VK_N);
    menuItem.addActionListener(getActionListener());
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
    menu.add(menuItem);
    menu.addSeparator();
    menuItem = new JMenuItem(Menu.LOAD_SCHEME, KeyEvent.VK_O);
    menuItem.addActionListener(getActionListener());
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
    menu.add(menuItem);
    menuItem = new JMenuItem(Menu.RELOAD_SCHEME, KeyEvent.VK_R);
    menuItem.addActionListener(getActionListener());
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK));
    menu.add(menuItem);
    menu.addSeparator();
    menuItem = new JMenuItem(Menu.SAVE_SCHEME, KeyEvent.VK_S);
    menuItem.addActionListener(getActionListener());
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
    menu.add(menuItem);
    menuItem = new JMenuItem(Menu.SAVE_SCHEME_AS);
    menuItem.addActionListener(getActionListener());
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK));
    menu.add(menuItem);
    menu.addSeparator();
    menuItem = new JMenuItem(Menu.DELETE_SCHEME, KeyEvent.VK_D);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);

    submenu = new JMenu(Menu.EXPORT_MENU);
    menu.add(submenu);
    //submenu.setMnemonic( KeyEvent.VK_E );

    SchemeExporter.makeSchemeExportMenu(submenu, getActionListener());

    // Export window graphics
    submenu.add(GraphicsExporter.getExportMenu());

    menu.addSeparator();
    menuItem = new JMenuItem(Menu.PRINT, KeyEvent.VK_P);
    menuItem.addActionListener(getActionListener());
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.CTRL_MASK));
    menu.add(menuItem);
    menu.addSeparator();
    menuItem = new JMenuItem(Menu.EXIT, KeyEvent.VK_X);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);
    menuBar.add(menu);
    menu = new JMenu(Menu.MENU_EDIT);
    menu.setMnemonic(KeyEvent.VK_E);

    menu.add(undoAction);
    menu.add(redoAction);
    menu.add(cloneAction);

    menuItem = new JMenuItem(Menu.SCHEME_FIND, KeyEvent.VK_F);
    menuItem.addActionListener(getActionListener());
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, ActionEvent.CTRL_MASK));
    menu.add(menuItem);

    menuItem = new JMenuItem(Menu.SELECT_ALL, KeyEvent.VK_A);
    menuItem.addActionListener(getActionListener());
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK));
    menu.add(menuItem);
    menuItem = new JMenuItem(Menu.CLEAR_ALL, KeyEvent.VK_C);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);

    final JCheckBoxMenuItem painterEnabled = new JCheckBoxMenuItem(Menu.CLASSPAINTER, true);
    painterEnabled.addActionListener(getActionListener());
    menu.add(painterEnabled);

    menu.getPopupMenu().addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
            // ignore
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            // ignore
        }

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            Canvas canvas = Editor.getInstance().getCurrentCanvas();
            if (canvas == null || !canvas.getPackage().hasPainters()) {
                painterEnabled.setVisible(false);
            } else {
                painterEnabled.setVisible(true);
                painterEnabled.setSelected(canvas.isEnableClassPainter());
            }
        }

    });

    menuBar.add(menu);

    menu = new JMenu(Menu.MENU_VIEW);
    menu.setMnemonic(KeyEvent.VK_V);
    gridCheckBox = new JCheckBoxMenuItem(Menu.GRID, RuntimeProperties.isShowGrid());
    gridCheckBox.setMnemonic('G');
    gridCheckBox.addActionListener(getActionListener());
    menu.add(gridCheckBox);

    ctrlCheckBox = new JCheckBoxMenuItem(Menu.CONTROL_PANEL, RuntimeProperties.isShowControls());
    ctrlCheckBox.setMnemonic('C');
    ctrlCheckBox.addActionListener(getActionListener());
    menu.add(ctrlCheckBox);

    showPortCheckBox = new JCheckBoxMenuItem(Menu.SHOW_PORTS, true);
    showPortCheckBox.addActionListener(getActionListener());
    menu.add(showPortCheckBox);

    showObjectNamesCheckBox = new JCheckBoxMenuItem(Menu.SHOW_NAMES, false);
    showObjectNamesCheckBox.addActionListener(getActionListener());
    menu.add(showObjectNamesCheckBox);

    //sync View with current canvas
    menu.getPopupMenu().addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            Canvas canvas;

            if ((canvas = getCurrentCanvas()) == null)
                return;

            gridCheckBox.setSelected(canvas.isGridVisible());
            ctrlCheckBox.setSelected(canvas.isCtrlPanelVisible());
            showPortCheckBox.setSelected(canvas.isDrawPorts());
            showObjectNamesCheckBox.setSelected(canvas.isShowObjectNames());
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            // ignore
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
            // ignore
        }

    });

    menuBar.add(menu);

    menu = new JMenu(Menu.MENU_PACKAGE);
    menu.setMnemonic(KeyEvent.VK_P);
    menuItem = new JMenuItem(Menu.LOAD, KeyEvent.VK_L);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);
    menuItem = new JMenuItem(Menu.RELOAD, KeyEvent.VK_R);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);
    menuItem = new JMenuItem(Menu.INFO, KeyEvent.VK_I);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);
    if (Desktop.isDesktopSupported()) {
        menuItem = new JMenuItem(Menu.BROWSE_PACKAGE, KeyEvent.VK_B);
        menuItem.addActionListener(getActionListener());
        menu.add(menuItem);
    }
    menuItem = new JMenuItem(Menu.CLOSE, KeyEvent.VK_C);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);
    menuItem = new JMenuItem(Menu.CLOSE_ALL);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);
    menuBar.add(menu);
    menu.add(new JSeparator());
    final JMenu submenuRecent = new JMenu(Menu.RECENT);
    submenuRecent.getPopupMenu().addPopupMenuListener(new PopupMenuListener() {

        final JMenuItem empty = new JMenuItem("Empty");

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {

            makeRecentSubMenu(submenuRecent);

            if (submenuRecent.getMenuComponentCount() == 0) {

                submenuRecent.add(empty);
                empty.setEnabled(false);

            } else {
                if (!((submenuRecent.getMenuComponentCount() == 1)
                        && (submenuRecent.getPopupMenu().getComponentIndex(empty) >= -1))) {
                    submenuRecent.remove(empty);
                }
            }

        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            // ignore
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
            // ignore
        }

    });
    menu.add(submenuRecent);
    final JMenu menuScheme = new JMenu(Menu.MENU_SCHEME);
    menuScheme.setMnemonic(KeyEvent.VK_S);
    makeSchemeMenu(menuScheme);

    menuScheme.getPopupMenu().addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {

            makeSchemeMenu(menuScheme);

        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            // ignore
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
            // ignore
        }

    });

    /*
     * menuItem = new JMenuItem("Planner");
     * menuItem.addActionListener(aListener); menuScheme.add(menuItem);
     * menuItem = new JMenuItem("Plan, compile, run");
     * menuItem.setActionCommand("Run");
     * menuItem.addActionListener(aListener); menuScheme.add(menuItem);
     */
    // menuScheme.setMnemonic(KeyEvent.VK_A);
    menuBar.add(menuScheme);
    menu = new JMenu(Menu.MENU_OPTIONS);
    menu.setMnemonic(KeyEvent.VK_O);

    menuItem = new JMenuItem(Menu.SETTINGS, KeyEvent.VK_S);
    menuItem.addActionListener(getActionListener());
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_J, ActionEvent.CTRL_MASK));
    menu.add(menuItem);

    menuItem = new JMenuItem(Menu.FONTS);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);

    menuItem = new JMenuItem(Menu.SAVE_SETTINGS);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);

    submenu = new JMenu(Menu.MENU_LAF);
    submenu.setMnemonic(KeyEvent.VK_L);
    Look.getInstance().createMenuItems(submenu);
    menu.add(submenu);
    menuBar.add(menu);

    makeToolsMenu(menuBar);

    menu = new JMenu(Menu.MENU_HELP);
    menu.setMnemonic(KeyEvent.VK_H);
    menuBar.add(menu);
    menuItem = new JMenuItem(Menu.DOCS, KeyEvent.VK_D);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);
}

From source file:components.MenuDemo.java

public JMenuBar createMenuBar() {
    JMenuBar menuBar;//from   w  ww .  j a  va 2  s  .  com
    JMenu menu, submenu;
    JMenuItem menuItem;
    JRadioButtonMenuItem rbMenuItem;
    JCheckBoxMenuItem cbMenuItem;

    //Create the menu bar.
    menuBar = new JMenuBar();

    //Build the first menu.
    menu = new JMenu("A Menu");
    menu.setMnemonic(KeyEvent.VK_A);
    menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items");
    menuBar.add(menu);

    //a group of JMenuItems
    menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T);
    //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything");
    menuItem.addActionListener(this);
    menu.add(menuItem);

    ImageIcon icon = createImageIcon("images/middle.gif");
    menuItem = new JMenuItem("Both text and icon", icon);
    menuItem.setMnemonic(KeyEvent.VK_B);
    menuItem.addActionListener(this);
    menu.add(menuItem);

    menuItem = new JMenuItem(icon);
    menuItem.setMnemonic(KeyEvent.VK_D);
    menuItem.addActionListener(this);
    menu.add(menuItem);

    //a group of radio button menu items
    menu.addSeparator();
    ButtonGroup group = new ButtonGroup();

    rbMenuItem = new JRadioButtonMenuItem("A radio button menu item");
    rbMenuItem.setSelected(true);
    rbMenuItem.setMnemonic(KeyEvent.VK_R);
    group.add(rbMenuItem);
    rbMenuItem.addActionListener(this);
    menu.add(rbMenuItem);

    rbMenuItem = new JRadioButtonMenuItem("Another one");
    rbMenuItem.setMnemonic(KeyEvent.VK_O);
    group.add(rbMenuItem);
    rbMenuItem.addActionListener(this);
    menu.add(rbMenuItem);

    //a group of check box menu items
    menu.addSeparator();
    cbMenuItem = new JCheckBoxMenuItem("A check box menu item");
    cbMenuItem.setMnemonic(KeyEvent.VK_C);
    cbMenuItem.addItemListener(this);
    menu.add(cbMenuItem);

    cbMenuItem = new JCheckBoxMenuItem("Another one");
    cbMenuItem.setMnemonic(KeyEvent.VK_H);
    cbMenuItem.addItemListener(this);
    menu.add(cbMenuItem);

    //a submenu
    menu.addSeparator();
    submenu = new JMenu("A submenu");
    submenu.setMnemonic(KeyEvent.VK_S);

    menuItem = new JMenuItem("An item in the submenu");
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK));
    menuItem.addActionListener(this);
    submenu.add(menuItem);

    menuItem = new JMenuItem("Another item");
    menuItem.addActionListener(this);
    submenu.add(menuItem);
    menu.add(submenu);

    //Build second menu in the menu bar.
    menu = new JMenu("Another Menu");
    menu.setMnemonic(KeyEvent.VK_N);
    menu.getAccessibleContext().setAccessibleDescription("This menu does nothing");
    menuBar.add(menu);

    return menuBar;
}

From source file:components.MenuSelectionManagerDemo.java

public JMenuBar createMenuBar() {
    JMenuBar menuBar;//from  ww  w .ja v  a  2 s  .  c  o  m
    JMenu menu, submenu;
    JMenuItem menuItem;
    JRadioButtonMenuItem rbMenuItem;
    JCheckBoxMenuItem cbMenuItem;

    //Create the menu bar.
    menuBar = new JMenuBar();

    //Build the first menu.
    menu = new JMenu("A Menu");
    menu.setMnemonic(KeyEvent.VK_A);
    menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items");
    menuBar.add(menu);

    //a group of JMenuItems
    menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T);
    //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything");
    menuItem.addActionListener(this);
    menu.add(menuItem);

    ImageIcon icon = createImageIcon("images/middle.gif");
    menuItem = new JMenuItem("Both text and icon", icon);
    menuItem.setMnemonic(KeyEvent.VK_B);
    menuItem.addActionListener(this);
    menu.add(menuItem);

    menuItem = new JMenuItem(icon);
    menuItem.setMnemonic(KeyEvent.VK_D);
    menuItem.addActionListener(this);
    menu.add(menuItem);

    //a group of radio button menu items
    menu.addSeparator();
    ButtonGroup group = new ButtonGroup();

    rbMenuItem = new JRadioButtonMenuItem("A radio button menu item");
    rbMenuItem.setSelected(true);
    rbMenuItem.setMnemonic(KeyEvent.VK_R);
    group.add(rbMenuItem);
    rbMenuItem.addActionListener(this);
    menu.add(rbMenuItem);

    rbMenuItem = new JRadioButtonMenuItem("Another one");
    rbMenuItem.setMnemonic(KeyEvent.VK_O);
    group.add(rbMenuItem);
    rbMenuItem.addActionListener(this);
    menu.add(rbMenuItem);

    //a group of check box menu items
    menu.addSeparator();
    cbMenuItem = new JCheckBoxMenuItem("A check box menu item");
    cbMenuItem.setMnemonic(KeyEvent.VK_C);
    cbMenuItem.addItemListener(this);
    menu.add(cbMenuItem);

    cbMenuItem = new JCheckBoxMenuItem("Another one");
    cbMenuItem.setMnemonic(KeyEvent.VK_H);
    cbMenuItem.addItemListener(this);
    menu.add(cbMenuItem);

    //a submenu
    menu.addSeparator();
    submenu = new JMenu("A submenu");
    submenu.setMnemonic(KeyEvent.VK_S);

    menuItem = new JMenuItem("An item in the submenu");
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK));
    menuItem.addActionListener(this);
    submenu.add(menuItem);

    menuItem = new JMenuItem("Another item");
    menuItem.addActionListener(this);
    submenu.add(menuItem);
    menu.add(submenu);

    //Build second menu in the menu bar.
    menu = new JMenu("Another Menu");
    menu.setMnemonic(KeyEvent.VK_N);
    menu.getAccessibleContext().setAccessibleDescription("This menu does nothing");
    menuBar.add(menu);

    Timer timer = new Timer(ONE_SECOND, new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            MenuElement[] path = MenuSelectionManager.defaultManager().getSelectedPath();
            for (int i = 0; i < path.length; i++) {
                if (path[i].getComponent() instanceof javax.swing.JMenuItem) {
                    JMenuItem mi = (JMenuItem) path[i].getComponent();
                    if ("".equals(mi.getText())) {
                        output.append("ICON-ONLY MENU ITEM > ");
                    } else {
                        output.append(mi.getText() + " > ");
                    }
                }
            }
            if (path.length > 0)
                output.append(newline);
        }
    });
    timer.start();
    return menuBar;
}

From source file:MenuDemo.java

public JMenuBar createMenuBar() {
    JMenuBar menuBar;//from   w w  w  . j av a 2s . c  o m
    JMenu menu, submenu;
    JMenuItem menuItem;
    JRadioButtonMenuItem rbMenuItem;
    JCheckBoxMenuItem cbMenuItem;

    //Create the menu bar.
    menuBar = new JMenuBar();

    //Build the first menu.
    menu = new JMenu("A Menu");
    menu.setMnemonic(KeyEvent.VK_A);
    menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items");
    menuBar.add(menu);

    //a group of JMenuItems
    menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T);
    //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything");
    menuItem.addActionListener(this);
    menu.add(menuItem);

    ImageIcon icon = createImageIcon("images/1.gif");
    menuItem = new JMenuItem("Both text and icon", icon);
    menuItem.setMnemonic(KeyEvent.VK_B);
    menuItem.addActionListener(this);
    menu.add(menuItem);

    menuItem = new JMenuItem(icon);
    menuItem.setMnemonic(KeyEvent.VK_D);
    menuItem.addActionListener(this);
    menu.add(menuItem);

    //a group of radio button menu items
    menu.addSeparator();
    ButtonGroup group = new ButtonGroup();

    rbMenuItem = new JRadioButtonMenuItem("A radio button menu item");
    rbMenuItem.setSelected(true);
    rbMenuItem.setMnemonic(KeyEvent.VK_R);
    group.add(rbMenuItem);
    rbMenuItem.addActionListener(this);
    menu.add(rbMenuItem);

    rbMenuItem = new JRadioButtonMenuItem("Another one");
    rbMenuItem.setMnemonic(KeyEvent.VK_O);
    group.add(rbMenuItem);
    rbMenuItem.addActionListener(this);
    menu.add(rbMenuItem);

    //a group of check box menu items
    menu.addSeparator();
    cbMenuItem = new JCheckBoxMenuItem("A check box menu item");
    cbMenuItem.setMnemonic(KeyEvent.VK_C);
    cbMenuItem.addItemListener(this);
    menu.add(cbMenuItem);

    cbMenuItem = new JCheckBoxMenuItem("Another one");
    cbMenuItem.setMnemonic(KeyEvent.VK_H);
    cbMenuItem.addItemListener(this);
    menu.add(cbMenuItem);

    //a submenu
    menu.addSeparator();
    submenu = new JMenu("A submenu");
    submenu.setMnemonic(KeyEvent.VK_S);

    menuItem = new JMenuItem("An item in the submenu");
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK));
    menuItem.addActionListener(this);
    submenu.add(menuItem);

    menuItem = new JMenuItem("Another item");
    menuItem.addActionListener(this);
    submenu.add(menuItem);
    menu.add(submenu);

    //Build second menu in the menu bar.
    menu = new JMenu("Another Menu");
    menu.setMnemonic(KeyEvent.VK_N);
    menu.getAccessibleContext().setAccessibleDescription("This menu does nothing");
    menuBar.add(menu);

    return menuBar;
}

From source file:com.prodigy4440.view.MainJFrame.java

public final void initComponents() {

    List<Image> icons = new LinkedList<>();
    icons.add(new ImageIcon(getClass().getResource("/com/prodigy4440/ited16x16.png")).getImage());
    icons.add(new ImageIcon(getClass().getResource("/com/prodigy4440/ited32x32.png")).getImage());
    icons.add(new ImageIcon(getClass().getResource("/com/prodigy4440/ited48x48.png")).getImage());
    icons.add(new ImageIcon(getClass().getResource("/com/prodigy4440/ited72x72.png")).getImage());

    this.setIconImages(icons);

    ActionHandler actionHandler = new ActionHandler(this);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setSize(620, 520);
    this.setLocationRelativeTo(null);
    this.setTitle("Untitled Document- IgboTextEditor");
    southJPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    SoftBevelBorder sbb = new SoftBevelBorder(SoftBevelBorder.LOWERED);
    southJPanel.setBorder(sbb);/*from   w w  w . j  ava 2 s.  com*/
    menuBar = new JMenuBar();

    fileJMenu = new JMenu("File");
    fileJMenu.setMnemonic('F');
    editJMenu = new JMenu("Edit");
    editJMenu.setMnemonic('E');
    formatJMenu = new JMenu("Format");
    formatJMenu.setMnemonic('A');
    viewJMenu = new JMenu("View");
    viewJMenu.setMnemonic('V');
    helpJMenu = new JMenu("Help");
    helpJMenu.setMnemonic('H');

    newDocumentJMenuItem = new JMenuItem("New");
    newDocumentJMenuItem.addActionListener(actionHandler);
    newDocumentJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, Event.CTRL_MASK));
    openJMenuItem = new JMenuItem("Open");
    openJMenuItem.addActionListener(actionHandler);
    openJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, Event.CTRL_MASK));
    saveJMenuItem = new JMenuItem("Save");
    saveJMenuItem.addActionListener(actionHandler);
    saveJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.CTRL_MASK));
    printJMenuItem = new JMenuItem("Print");
    printJMenuItem.addActionListener(actionHandler);
    printJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, Event.CTRL_MASK));
    exitJMenuItem = new JMenuItem("Exit");
    exitJMenuItem.addActionListener(actionHandler);

    undoJMenuItem = new JMenuItem("Undo");
    undoJMenuItem.addActionListener(actionHandler);
    undoJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, Event.CTRL_MASK));
    redoJMenuItem = new JMenuItem("Redo");
    redoJMenuItem.addActionListener(actionHandler);
    redoJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Y, Event.CTRL_MASK));
    copyJMenuItem = new JMenuItem("Copy");
    copyJMenuItem.addActionListener(actionHandler);
    copyJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, Event.CTRL_MASK));
    cutJMenuItem = new JMenuItem("Cut");
    cutJMenuItem.addActionListener(actionHandler);
    cutJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, Event.CTRL_MASK));
    pasteJMenuItem = new JMenuItem("Paste");
    pasteJMenuItem.addActionListener(actionHandler);
    pasteJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, Event.CTRL_MASK));
    deleteJMenuItem = new JMenuItem("Delete");
    deleteJMenuItem.addActionListener(actionHandler);
    deleteJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, Event.CTRL_MASK));
    selectAllJMenuItem = new JMenuItem("Select All");
    selectAllJMenuItem.addActionListener(actionHandler);
    selectAllJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, Event.CTRL_MASK));
    findJMenuItem = new JMenuItem("Find");
    findJMenuItem.addActionListener(actionHandler);
    findJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, Event.CTRL_MASK));
    replaceJMenuItem = new JMenuItem("Replace");
    replaceJMenuItem.addActionListener(actionHandler);
    replaceJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, Event.CTRL_MASK));

    wordWrapJCheckBoxMenuItem = new JCheckBoxMenuItem("Word Wrap");
    wordWrapJCheckBoxMenuItem.addActionListener(actionHandler);
    wordWrapJCheckBoxMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, Event.CTRL_MASK));
    fontJMenuItem = new JMenuItem("Font");
    fontJMenuItem.addActionListener(actionHandler);
    colorJMenuItem = new JMenuItem("Color");
    colorJMenuItem.addActionListener(actionHandler);

    statusBarJCheckBoxMenuItem = new JCheckBoxMenuItem("Status Bar");
    statusBarJCheckBoxMenuItem.addActionListener(actionHandler);
    statusBarJCheckBoxMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.ALT_MASK));

    helpJMenuItem = new JMenuItem("Help");
    helpJMenuItem.addActionListener(actionHandler);
    helpJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, Event.CTRL_MASK));
    aboutJMenuItem = new JMenuItem("About");
    aboutJMenuItem.addActionListener(actionHandler);

    statusJLabel = new JLabel("Status:");

    //Main text area setup
    textArea = new JTextArea();
    undoManager = new UndoManager();
    wordSearcher = new WordSearcher(textArea);
    textArea.setBorder(BorderFactory.createMatteBorder(4, 4, 4, 4, Color.WHITE));
    document = textArea.getDocument();
    document.addUndoableEditListener(new UndoableEditListener() {
        @Override
        public void undoableEditHappened(UndoableEditEvent e) {
            undoManager.addEdit(e.getEdit());
        }
    });

    font = new Font("Tahoma", Font.PLAIN, 16);
    textArea.setFont(font);
    color = Color.BLUE;
    textArea.setForeground(color);

    undoManager = new UndoManager();

    fileJMenu.add(newDocumentJMenuItem);
    fileJMenu.addSeparator();
    fileJMenu.add(openJMenuItem);
    fileJMenu.add(saveJMenuItem);
    fileJMenu.addSeparator();
    fileJMenu.add(printJMenuItem);
    fileJMenu.addSeparator();
    fileJMenu.add(exitJMenuItem);

    editJMenu.add(undoJMenuItem);
    editJMenu.add(redoJMenuItem);
    editJMenu.addSeparator();
    editJMenu.add(copyJMenuItem);
    editJMenu.add(cutJMenuItem);
    editJMenu.add(pasteJMenuItem);
    editJMenu.addSeparator();
    editJMenu.add(deleteJMenuItem);
    editJMenu.add(selectAllJMenuItem);
    editJMenu.addSeparator();
    editJMenu.add(findJMenuItem);
    editJMenu.add(replaceJMenuItem);

    formatJMenu.add(wordWrapJCheckBoxMenuItem);
    formatJMenu.add(fontJMenuItem);
    formatJMenu.add(colorJMenuItem);

    viewJMenu.add(statusBarJCheckBoxMenuItem);

    helpJMenu.add(helpJMenuItem);
    helpJMenu.add(aboutJMenuItem);

    menuBar.add(fileJMenu);
    menuBar.add(editJMenu);
    menuBar.add(formatJMenu);
    menuBar.add(viewJMenu);
    menuBar.add(helpJMenu);

    southJPanel.setVisible(false);
    southJPanel.add(statusJLabel);
    //JScrollPane setup
    JScrollPane scrollPane = new JScrollPane(textArea);
    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    //setting uo the Jframe
    this.setJMenuBar(menuBar);
    this.add(scrollPane, BorderLayout.CENTER);
    this.add(southJPanel, BorderLayout.SOUTH);
    textArea.addMouseListener(new MouseInputListener() {

        @Override
        public void mouseClicked(MouseEvent e) {
            Highlighter h = textArea.getHighlighter();
            h.removeAllHighlights();
        }

        @Override
        public void mousePressed(MouseEvent e) {
            Highlighter h = textArea.getHighlighter();
            h.removeAllHighlights();
        }

        @Override
        public void mouseReleased(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }

        @Override
        public void mouseDragged(MouseEvent e) {
        }

        @Override
        public void mouseMoved(MouseEvent e) {
        }
    });

    textArea.addKeyListener(new IgboKeyListener(textArea));

}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakAnnotationCalibrationPanel.java

protected void createActions() {
    theActionManager.add("accunit=da", FileUtils.defaultThemeManager.getImageIcon("da"), "Show accuracy in Da",
            -1, "", this);
    theActionManager.add("accunit=ppm", FileUtils.defaultThemeManager.getImageIcon("ppm"),
            "Show accuracy in PPM", -1, "", this);

    theActionManager.add("new", FileUtils.defaultThemeManager.getImageIcon("new"), "Clear", KeyEvent.VK_N, "",
            this);

    theActionManager.add("close", FileUtils.defaultThemeManager.getImageIcon("close"), "Close structure",
            KeyEvent.VK_S, "", this);
    theActionManager.add("last", FileUtils.defaultThemeManager.getImageIcon("last"), "Last structure",
            KeyEvent.VK_L, "", this);
    theActionManager.add("next", FileUtils.defaultThemeManager.getImageIcon("next"), "Next structure",
            KeyEvent.VK_N, "", this);

    theActionManager.add("print", FileUtils.defaultThemeManager.getImageIcon("print"), "Print...",
            KeyEvent.VK_P, "", this);

    //theActionManager.add("undo",FileUtils.defaultThemeManager.getImageIcon("undo"),"Undo",KeyEvent.VK_U, "",this);
    //theActionManager.add("redo",FileUtils.defaultThemeManager.getImageIcon("redo"),"Redo", KeyEvent.VK_R, "",this);

    theActionManager.add("arrow", FileUtils.defaultThemeManager.getImageIcon("arrow"), "Activate zoom", -1, "",
            this);
    theActionManager.add("hand", FileUtils.defaultThemeManager.getImageIcon("hand"), "Activate moving", -1, "",
            this);

    theActionManager.add("zoomnone", FileUtils.defaultThemeManager.getImageIcon("zoomnone"), "Reset zoom", -1,
            "", this);
    theActionManager.add("zoomin", FileUtils.defaultThemeManager.getImageIcon("zoomin"), "Zoom in", -1, "",
            this);
    theActionManager.add("zoomout", FileUtils.defaultThemeManager.getImageIcon("zoomout"), "Zoom out", -1, "",
            this);
}

From source file:MenuSelectionManagerDemo.java

public JMenuBar createMenuBar() {
    JMenuBar menuBar;//from  ww  w  .  j a va2  s. c o  m
    JMenu menu, submenu;
    JMenuItem menuItem;
    JRadioButtonMenuItem rbMenuItem;
    JCheckBoxMenuItem cbMenuItem;

    //Create the menu bar.
    menuBar = new JMenuBar();

    //Build the first menu.
    menu = new JMenu("A Menu");
    menu.setMnemonic(KeyEvent.VK_A);
    menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items");
    menuBar.add(menu);

    //a group of JMenuItems
    menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T);
    //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything");
    menuItem.addActionListener(this);
    menu.add(menuItem);

    ImageIcon icon = createImageIcon("1.gif");
    menuItem = new JMenuItem("Both text and icon", icon);
    menuItem.setMnemonic(KeyEvent.VK_B);
    menuItem.addActionListener(this);
    menu.add(menuItem);

    menuItem = new JMenuItem(icon);
    menuItem.setMnemonic(KeyEvent.VK_D);
    menuItem.addActionListener(this);
    menu.add(menuItem);

    //a group of radio button menu items
    menu.addSeparator();
    ButtonGroup group = new ButtonGroup();

    rbMenuItem = new JRadioButtonMenuItem("A radio button menu item");
    rbMenuItem.setSelected(true);
    rbMenuItem.setMnemonic(KeyEvent.VK_R);
    group.add(rbMenuItem);
    rbMenuItem.addActionListener(this);
    menu.add(rbMenuItem);

    rbMenuItem = new JRadioButtonMenuItem("Another one");
    rbMenuItem.setMnemonic(KeyEvent.VK_O);
    group.add(rbMenuItem);
    rbMenuItem.addActionListener(this);
    menu.add(rbMenuItem);

    //a group of check box menu items
    menu.addSeparator();
    cbMenuItem = new JCheckBoxMenuItem("A check box menu item");
    cbMenuItem.setMnemonic(KeyEvent.VK_C);
    cbMenuItem.addItemListener(this);
    menu.add(cbMenuItem);

    cbMenuItem = new JCheckBoxMenuItem("Another one");
    cbMenuItem.setMnemonic(KeyEvent.VK_H);
    cbMenuItem.addItemListener(this);
    menu.add(cbMenuItem);

    //a submenu
    menu.addSeparator();
    submenu = new JMenu("A submenu");
    submenu.setMnemonic(KeyEvent.VK_S);

    menuItem = new JMenuItem("An item in the submenu");
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK));
    menuItem.addActionListener(this);
    submenu.add(menuItem);

    menuItem = new JMenuItem("Another item");
    menuItem.addActionListener(this);
    submenu.add(menuItem);
    menu.add(submenu);

    //Build second menu in the menu bar.
    menu = new JMenu("Another Menu");
    menu.setMnemonic(KeyEvent.VK_N);
    menu.getAccessibleContext().setAccessibleDescription("This menu does nothing");
    menuBar.add(menu);

    Timer timer = new Timer(ONE_SECOND, new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            MenuElement[] path = MenuSelectionManager.defaultManager().getSelectedPath();
            for (int i = 0; i < path.length; i++) {
                if (path[i].getComponent() instanceof javax.swing.JMenuItem) {
                    JMenuItem mi = (JMenuItem) path[i].getComponent();
                    if ("".equals(mi.getText())) {
                        output.append("ICON-ONLY MENU ITEM > ");
                    } else {
                        output.append(mi.getText() + " > ");
                    }
                }
            }
            if (path.length > 0)
                output.append(newline);
        }
    });
    timer.start();
    return menuBar;
}