Example usage for javax.swing JMenuItem JMenuItem

List of usage examples for javax.swing JMenuItem JMenuItem

Introduction

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

Prototype

public JMenuItem(String text, int mnemonic) 

Source Link

Document

Creates a JMenuItem with the specified text and keyboard mnemonic.

Usage

From source file:adams.gui.tools.FileMonitorPanel.java

/**
 * Creates a menu bar (singleton per panel object). Can be used in frames.
 *
 * @return      the menu bar//ww w .  ja v a2 s  . c o  m
 */
@Override
public JMenuBar getMenuBar() {
    JMenuBar result;
    JMenu menu;
    JMenu submenu;
    JMenuItem menuitem;

    if (m_MenuBar == null) {
        result = new JMenuBar();

        // File
        menu = new JMenu("File");
        result.add(menu);
        menu.setMnemonic('F');
        menu.addChangeListener((ChangeEvent e) -> updateMenu());

        menuitem = new JMenuItem("Open...", GUIHelper.getIcon("open.gif"));
        menuitem.setMnemonic('O');
        menuitem.setAccelerator(GUIHelper.getKeyStroke("ctrl pressed O"));
        menuitem.addActionListener((ActionEvent e) -> open());
        menu.add(menuitem);
        m_MenuItemOpen = menuitem;

        // File/Recent files
        submenu = new JMenu("Open recent");
        menu.add(submenu);
        m_RecentFilesHandler = new RecentFilesHandler<>(SESSION_FILE, 5, submenu);
        m_RecentFilesHandler.addRecentItemListener(new RecentItemListener<JMenu, File>() {
            public void recentItemAdded(RecentItemEvent<JMenu, File> e) {
                // ignored
            }

            public void recentItemSelected(RecentItemEvent<JMenu, File> e) {
                open(e.getItem());
            }
        });
        m_MenuItemOpenRecent = submenu;

        menu.addSeparator();

        menuitem = new JMenuItem("Close", GUIHelper.getIcon("exit.png"));
        menuitem.setMnemonic('C');
        menuitem.setAccelerator(GUIHelper.getKeyStroke("ctrl pressed Q"));
        menuitem.addActionListener((ActionEvent e) -> close());
        menu.add(menuitem);
        m_MenuItemClose = menuitem;

        // update menu
        m_MenuBar = result;
        updateMenu();
    } else {
        result = m_MenuBar;
    }

    return result;
}

From source file:edu.purdue.cc.bionet.ui.ClusteringDisplayPanel.java

/**
 * A class for displaying information about a Clustering
 */// ww w .j  a v a 2s  .com
public ClusteringDisplayPanel() {
    super(new BorderLayout());
    Language language = Settings.getLanguage();
    this.addComponentListener(new InitialSetup());
    this.menuBar = new JMenuBar();
    this.groupsMenu = new JMenu(language.get("Groups"));
    this.groupsMenu.setMnemonic(KeyEvent.VK_G);
    this.removeSampleGroupsMenuItem = new JMenuItem(language.get("Reset Sample Groups"), KeyEvent.VK_R);
    this.chooseSampleGroupsMenuItem = new JMenuItem(language.get("Choose Sample Groups"), KeyEvent.VK_C);
    this.recomputeMenuItem = new JMenuItem(Settings.getLanguage().get("Recompute/Set Parameters"));
    this.recomputeMenuItem.addActionListener(this);
    this.groupsMenu.add(this.removeSampleGroupsMenuItem);
    this.groupsMenu.add(this.chooseSampleGroupsMenuItem);
    this.chooseSampleGroupsMenuItem.addActionListener(this);
    this.removeSampleGroupsMenuItem.addActionListener(this);
    this.add(menuBar, BorderLayout.NORTH);
    this.menuBar.add(this.groupsMenu);
    this.menuBar.add(this.recomputeMenuItem);
}

From source file:com.documentgenerator.view.MainWindow.java

private ArrayList<JMenuItem> getMenuItem(JSONArray jsonMenuItems) {
    int count = jsonMenuItems.size(), i;
    menuItems = new ArrayList<>();
    for (i = 0; i < count; i++) {
        jsonMenuItem = (JSONObject) jsonMenuItems.get(i);
        String menuTitle = (String) jsonMenuItem.get("menuTitle");
        ImageIcon imageIcon = new ImageIcon(
                ClassLoader.getSystemResource((String) jsonMenuItem.get("imageIcon")));

        menuItem = new JMenuItem(menuTitle, imageIcon);
        String className = (String) jsonMenuItem.get("className");
        String shortcut = (String) jsonMenuItem.get("shortcut");
        Boolean hasSeparator = (Boolean) jsonMenuItem.get("separator");
        Boolean hasToolbar = (Boolean) jsonMenuItem.get("hasToolbar");

        if (!Strings.isNullOrEmpty(shortcut)) {
            menuItem.setAccelerator(utils.getKeyStroke(shortcut));
        }//from   w w  w  . ja  v  a2  s. c  o m

        if (className.equals("string")) {
            menuItem.setActionCommand(menuTitle);
            menuItem.addActionListener(actionListener);
        } else {
            menuItem.setActionCommand(className);
            menuItem.addActionListener(new MenuItemActionListener(this, className));
        }
        menu.add(menuItem);

        if (hasToolbar) {
            JButton button = new JButton(imageIcon);
            button.setToolTipText(menuTitle);
            button.addActionListener(new MenuItemActionListener(this, className));
            toolBar.add(button);
        }
    }
    return menuItems;
}

From source file:net.chaosserver.timelord.swingui.TimelordMenu.java

/**
 * Creates the file menu./*from  w w w . j a  va 2 s  .  c  o  m*/
 *
 * @return the new file menu
 */
protected JMenu createFileMenu() {
    JMenu fileMenu = new JMenu(resourceBundle.getString(RROOT + ".fileMenuName"));
    JMenuItem menuItem;

    fileMenu.setMnemonic(KeyEvent.VK_F);

    JMenu exportMenu = new JMenu(resourceBundle.getString(RROOT + ".file.export"));
    exportMenu.setMnemonic(KeyEvent.VK_A);

    menuItem = new JMenuItem(resourceBundle.getString(RROOT + ".file.export.jordan"), KeyEvent.VK_J);

    menuItem.setToolTipText(resourceBundle.getString(RROOT + ".file.export.jordan.tooltip"));

    menuItem.setActionCommand(ACTION_EXPORT_JORDAN);
    menuItem.addActionListener(this);
    exportMenu.add(menuItem);

    menuItem = new JMenuItem(resourceBundle.getString(RROOT + ".file.export.doug"), KeyEvent.VK_D);

    menuItem.setToolTipText("For Losers");
    menuItem.setActionCommand(ACTION_EXPORT_DOUG);
    menuItem.addActionListener(this);
    exportMenu.add(menuItem);

    exportMenu.addSeparator();
    menuItem = new JMenuItem("XML...", KeyEvent.VK_X);
    menuItem.setActionCommand(ACTION_EXPORT_XML);
    menuItem.addActionListener(this);
    exportMenu.add(menuItem);

    fileMenu.add(exportMenu);

    if (!OsUtil.isMac()) {
        fileMenu.addSeparator();
        menuItem = new JMenuItem("Exit", KeyEvent.VK_X);
        menuItem.setActionCommand(ACTION_EXIT);
        menuItem.addActionListener(this);
        fileMenu.add(menuItem);
    }

    return fileMenu;
}

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  w  w.j  a v a  2s.  c om
    jmenu.addSeparator();
    JMenuItem jmenuitem1 = new JMenuItem("Exit", 120);
    jmenuitem1.setActionCommand("EXIT");
    jmenuitem1.addActionListener(this);
    jmenu.add(jmenuitem1);
    jmenubar.add(jmenu);
    return jmenubar;
}

From source file:net.sf.jabref.gui.openoffice.OpenOfficePanel.java

public JMenuItem getMenuItem() {
    if (preferences.showPanel()) {
        manager.show(getName());/*from  w  ww  .  j a va 2 s  .  co  m*/
    }
    JMenuItem item = new JMenuItem(Localization.lang("OpenOffice/LibreOffice connection"),
            IconTheme.getImage("openoffice"));
    item.addActionListener(event -> manager.show(getName()));
    return item;
}

From source file:com.alvermont.javascript.tools.shell.ShellJSConsole.java

public ShellJSConsole(String[] args) {
    super("Rhino JavaScript Console");

    final JMenuBar menubar = new JMenuBar();
    createFileChooser();//  w ww  . j a  v a 2s  .  co  m

    final String[] fileItems = { "Load...", "Close" };
    final String[] fileCmds = { "Load", "Close" };
    final char[] fileShortCuts = { 'L', 'X' };
    final String[] editItems = { "Cut", "Copy", "Paste" };
    final char[] editShortCuts = { 'T', 'C', 'P' };
    final JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic('F');

    final JMenu editMenu = new JMenu("Edit");
    editMenu.setMnemonic('E');

    for (int i = 0; i < fileItems.length; ++i) {
        final JMenuItem item = new JMenuItem(fileItems[i], fileShortCuts[i]);
        item.setActionCommand(fileCmds[i]);
        item.addActionListener(this);
        fileMenu.add(item);
    }

    for (int i = 0; i < editItems.length; ++i) {
        final JMenuItem item = new JMenuItem(editItems[i], editShortCuts[i]);
        item.addActionListener(this);
        editMenu.add(item);
    }

    final ButtonGroup group = new ButtonGroup();
    menubar.add(fileMenu);
    menubar.add(editMenu);
    setJMenuBar(menubar);
    this.consoleTextArea = new ShellConsoleTextArea(args);

    final JScrollPane scroller = new JScrollPane(this.consoleTextArea);
    setContentPane(scroller);
    this.consoleTextArea.setRows(24);
    this.consoleTextArea.setColumns(80);
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            setVisible(false);
        }
    });
    pack();
    setVisible(true);
    // System.setIn(consoleTextArea.getIn());
    // System.setOut(consoleTextArea.getOut());
    // System.setErr(consoleTextArea.getErr());
    ShellMain.setIn(this.consoleTextArea.getIn());
    ShellMain.setOut(this.consoleTextArea.getOut());
    ShellMain.setErr(this.consoleTextArea.getErr());

    // we don't do this here as we want to separate construction from
    // the run thread
    this.args = args;

    //ShellMain.exec(args);
}

From source file:edu.purdue.cc.bionet.ui.DistributionAnalysisDisplayPanel.java

/**
 * Creates a new DistributionAnalysisDisplayPanel.
 *//*from w  ww. j a  v a  2s .co  m*/
public DistributionAnalysisDisplayPanel() {
    super(new BorderLayout());
    Language language = Settings.getLanguage();
    this.menuBar = new JMenuBar();
    this.curveFittingMenu = new JMenu(language.get("Curve Fitting"));
    this.curveFittingMenu.setMnemonic(KeyEvent.VK_C);
    this.groupsMenu = new JMenu(language.get("Groups"));
    this.groupsMenu.setMnemonic(KeyEvent.VK_G);
    this.viewMenu = new JMenu(language.get("View"));
    this.viewMenu.setMnemonic(KeyEvent.VK_V);
    this.removeSampleGroupsMenuItem = new JMenuItem(language.get("Reset Sample Groups"), KeyEvent.VK_R);
    this.chooseSampleGroupsMenuItem = new JMenuItem(language.get("Choose Sample Groups"), KeyEvent.VK_C);
    this.fitSelectorPanel = new JPanel(new GridLayout(4, 1));
    this.noFitButton = new JRadioButtonMenuItem(language.get("No Fit"));
    this.robustFitButton = new JRadioButtonMenuItem(language.get("Robust Linear Fit"));
    this.chiSquareFitButton = new JRadioButtonMenuItem(language.get("Chi Square Fit"));
    this.fitButtonGroup = new ButtonGroup();
    this.fitButtonGroup.add(this.noFitButton);
    this.fitButtonGroup.add(this.robustFitButton);
    this.fitButtonGroup.add(this.chiSquareFitButton);
    this.noFitButton.setSelected(true);
    this.hideOutliersViewMenuItem = new JMenuItem(language.get("Hide Current Outliers"));
    this.curveFittingMenu.add(this.noFitButton);
    this.curveFittingMenu.add(this.robustFitButton);
    this.curveFittingMenu.add(this.chiSquareFitButton);
    this.groupsMenu.add(this.removeSampleGroupsMenuItem);
    this.groupsMenu.add(this.chooseSampleGroupsMenuItem);
    this.viewMenu.add(this.hideOutliersViewMenuItem);
    this.chooseSampleGroupsMenuItem.addActionListener(this);
    this.removeSampleGroupsMenuItem.addActionListener(this);
    this.hideOutliersViewMenuItem.addActionListener(this);
    this.add(menuBar, BorderLayout.NORTH);
    this.menuBar.add(this.curveFittingMenu);
    this.menuBar.add(this.groupsMenu);
    this.menuBar.add(this.viewMenu);
}

From source file:fi.smaa.jsmaa.gui.SMAA2GUIFactory.java

@Override
protected JMenu buildResultsMenu() {
    JMenu resultsMenu = new JMenu("Results");
    resultsMenu.setMnemonic('r');
    JMenuItem cwItem = new JMenuItem("Central weight vectors",
            ImageFactory.IMAGELOADER.getIcon(FileNames.ICON_CENTRALWEIGHTS));
    cwItem.setMnemonic('c');
    JMenuItem racsItem = new JMenuItem("Rank acceptability indices",
            ImageFactory.IMAGELOADER.getIcon(FileNames.ICON_RANKACCEPTABILITIES));
    racsItem.setMnemonic('r');

    cwItem.addActionListener(new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            Focuser.focus(tree, treeModel, treeModel.getCentralWeightsNode());
        }/*from   ww w.ja v  a 2 s . c  om*/
    });

    racsItem.addActionListener(new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            Focuser.focus(tree, treeModel, treeModel.getRankAcceptabilitiesNode());
        }
    });

    resultsMenu.add(cwItem);
    resultsMenu.add(racsItem);
    return resultsMenu;
}

From source file:net.java.sip.communicator.impl.osdependent.jdic.TrayMenuFactory.java

/**
 * Creates a tray menu with the given <tt>name</tt>, text given by
 * <tt>textID</tt> and icon given by <tt>iconID</tt>. The <tt>listener</tt>
 * is handling item events and the <tt>swing</tt> value indicates if we
 * should create a Swing menu item or and an AWT item.
 * @param name the name of the item/*w w w  .  j a  v a  2  s  . c om*/
 * @param textID the identifier of the text in the localization resources
 * @param iconID the identifier of the icon in the image resources
 * @param listener the <tt>ActionListener</tt> handling action events
 * @param swing indicates if we should create a Swing menu item or an AWT
 * item
 * @return a reference to the newly created item
 */
private static Object createTrayMenuItem(String name, String textID, String iconID, ActionListener listener,
        boolean swing) {
    String text = Resources.getString(textID);
    Object trayMenuItem;
    if (swing) {
        JMenuItem menuItem = new JMenuItem(text, Resources.getImage(iconID));
        menuItem.setName(name);
        menuItem.addActionListener(listener);
        trayMenuItem = menuItem;
    } else {
        MenuItem menuItem = new MenuItem(text);
        menuItem.setName(name);
        menuItem.addActionListener(listener);
        trayMenuItem = menuItem;
    }
    return trayMenuItem;
}