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(Action a) 

Source Link

Document

Creates a menu item whose properties are taken from the specified Action.

Usage

From source file:SwingMenus.java

public void init() {
    ML ml = new ML();
    CMIL cmil = new CMIL();
    safety[0].setActionCommand("Guard");
    safety[0].setMnemonic(KeyEvent.VK_G);
    safety[0].addItemListener(cmil);//from w  w  w.  ja  va 2s.c o m
    safety[1].setActionCommand("Hide");
    safety[1].setMnemonic(KeyEvent.VK_H);
    safety[1].addItemListener(cmil);
    other[0].addActionListener(new FooL());
    other[1].addActionListener(new BarL());
    other[2].addActionListener(new BazL());
    FL fl = new FL();
    for (int i = 0; i < flavors.length; i++) {
        JMenuItem mi = new JMenuItem(flavors[i]);
        mi.addActionListener(fl);
        m.add(mi);
        // Add separators at intervals:
        if ((i + 1) % 3 == 0)
            m.addSeparator();
    }
    for (int i = 0; i < safety.length; i++)
        s.add(safety[i]);
    s.setMnemonic(KeyEvent.VK_A);
    f.add(s);
    f.setMnemonic(KeyEvent.VK_F);
    for (int i = 0; i < file.length; i++) {
        file[i].addActionListener(fl);
        f.add(file[i]);
    }
    mb1.add(f);
    mb1.add(m);
    setJMenuBar(mb1);
    t.setEditable(false);
    Container cp = getContentPane();
    cp.add(t, BorderLayout.CENTER);
    // Set up the system for swapping menus:
    b.addActionListener(new BL());
    b.setMnemonic(KeyEvent.VK_S);
    cp.add(b, BorderLayout.NORTH);
    for (int i = 0; i < other.length; i++)
        fooBar.add(other[i]);
    fooBar.setMnemonic(KeyEvent.VK_B);
    mb2.add(fooBar);
}

From source file:gdt.jgui.tool.JTextEncrypter.java

/**
 * Get context menu.//  w  w w  .  j  a  va  2s .c  o m
 * @return the context menu. 
 */
@Override
public JMenu getContextMenu() {
    menu = new JMenu("Context");
    menu.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            menu.removeAll();
            JMenuItem doneItem = new JMenuItem("Done");
            doneItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    if (requesterResponseLocator$ != null) {
                        try {
                            byte[] ba = Base64.decodeBase64(requesterResponseLocator$);
                            String responseLocator$ = new String(ba, "UTF-8");
                            text$ = textArea.getText();
                            responseLocator$ = Locator.append(responseLocator$, JTextEditor.TEXT, text$);
                            //System.out.println("TextEditor:done:response locator="+responseLocator$);
                            JConsoleHandler.execute(console, responseLocator$);
                        } catch (Exception ee) {
                            Logger.getLogger(JTextEncrypter.class.getName()).severe(ee.toString());
                        }
                    } else
                        console.back();

                }
            });
            menu.add(doneItem);
            JMenuItem cancelItem = new JMenuItem("Cancel");
            cancelItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    console.back();
                }
            });
            menu.add(cancelItem);
            char[] master = passwordField.getPassword();
            //            System.out.println("Textencoder:context menu:master="+master.length);
            if (master.length > 6) {
                menu.addSeparator();
                JMenuItem encryptItem = new JMenuItem("Encrypt");
                encryptItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        char[] master = passwordField.getPassword();
                        DesEncrypter desEncrypter = new DesEncrypter(master);
                        String encrypted$ = desEncrypter.encrypt(textArea.getText());
                        textArea.setText(encrypted$);
                    }
                });

                menu.add(encryptItem);
                JMenuItem decryptItem = new JMenuItem("Decrypt");
                decryptItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        char[] master = passwordField.getPassword();
                        DesEncrypter desEncrypter = new DesEncrypter(master);
                        String decrypted$ = desEncrypter.decrypt(textArea.getText());
                        if (decrypted$ != null && decrypted$.length() > 0)
                            textArea.setText(decrypted$);
                    }
                });
                menu.add(decryptItem);
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {
        }

        @Override
        public void menuCanceled(MenuEvent e) {
        }
    });
    return menu;
}

From source file:com.haulmont.cuba.desktop.sys.MenuBuilder.java

private void createSubMenu(JMenu jMenu, MenuItem item) {
    List<MenuItem> itemChildren = new ArrayList<>(item.getChildren());
    CollectionUtils.filter(itemChildren, object -> object.isPermitted(userSession));

    List<MenuItemContainer> items = new ArrayList<>();

    // prepare menu items
    for (MenuItem child : itemChildren) {
        if (child.getChildren().isEmpty()) {
            if (child.isSeparator()) {
                items.add(new MenuItemContainer());
            } else {
                JMenuItem jMenuItem = new JMenuItem(menuConfig.getItemCaption(child.getId()));
                jMenuItem.setName(child.getId());
                assignCommand(jMenuItem, child);
                assignShortcut(jMenuItem, child);
                items.add(new MenuItemContainer(jMenuItem));
            }/*from w ww .  ja v  a 2s.c  om*/
        } else {
            JMenu jChildMenu = new JMenu(menuConfig.getItemCaption(child.getId()));
            createSubMenu(jChildMenu, child);
            if (!isMenuEmpty(jChildMenu)) {
                items.add(new MenuItemContainer(jChildMenu));
            }
        }
    }

    // remove unnecessary separators
    if (!items.isEmpty()) {
        Iterator<MenuItemContainer> iterator = items.iterator();
        JMenuItem menuItem = getNextMenuItem(iterator);
        boolean useSeparator = false;

        while (menuItem != null) {
            if (useSeparator)
                jMenu.addSeparator();

            jMenu.add(menuItem);

            useSeparator = false;
            menuItem = null;

            if (iterator.hasNext()) {
                MenuItemContainer itemContainer = iterator.next();
                if (!itemContainer.isSeparator())
                    menuItem = itemContainer.getMenuItem();
                else {
                    menuItem = getNextMenuItem(iterator);
                    useSeparator = true;
                }
            }
        }
    }
}

From source file:net.erdfelt.android.sdkfido.ui.SdkFidoFrame.java

private JMenu createFileMenu() {
    JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic('f');

    JMenuItem fileExit = new JMenuItem("Exit");
    fileExit.setMnemonic('x');
    fileExit.setActionCommand("exit");
    fileExit.addActionListener(actionMapper);
    fileMenu.add(fileExit);//from  ww w.  jav  a 2  s. c  om

    return fileMenu;
}

From source file:fi.elfcloud.client.tree.ClusterNode.java

private void populatePopupMenu(JPopupMenu menu, BeaverGUI gui) {
    JMenuItem item;//from w w  w  .  j a  va2  s  .c o  m
    item = new JMenuItem(Messages.getString("ClusterNode.popup_modify")); //$NON-NLS-1$
    item.setActionCommand(Integer.toString(gui.ACTION_MODIFY));
    item.addActionListener(gui);
    item.setIcon(new ImageIcon(BeaverGUI.class.getResource("icons/modify_rename16.png"))); //$NON-NLS-1$
    menu.add(item);

    item = new JMenuItem(Messages.getString("ClusterNode.popup_information")); //$NON-NLS-1$
    item.setIcon(new ImageIcon(BeaverGUI.class.getResource("icons/info_file16.png"))); //$NON-NLS-1$
    item.setActionCommand(Integer.toString(gui.ACTION_INFORMATION));
    item.addActionListener(gui);
    menu.add(item);
    menu.addSeparator();

    item = new JMenuItem(Messages.getString("ClusterNode.popup_delete")); //$NON-NLS-1$
    item.setActionCommand(Integer.toString(gui.ACTION_DELETE));
    item.addActionListener(gui);
    item.setIcon(new ImageIcon(BeaverGUI.class.getResource("icons/delete16.png"))); //$NON-NLS-1$
    menu.add(item);
}

From source file:it.unibas.spicygui.controllo.provider.composition.MyPopupProviderWidgetChainComposition.java

private void createPopupMenu() {
    menu = new JPopupMenu("Popup menu");

    JMenuItem itemDeleteWidget;//from w ww. jav  a 2 s  . com

    itemDeleteWidget = new JMenuItem(NbBundle.getMessage(Costanti.class, Costanti.DELETE_WIDGET_COMPOSITION));
    itemDeleteWidget.setActionCommand(DELETE);
    itemDeleteWidget.addActionListener(this);
    menu.add(itemDeleteWidget);

    itemLoadDataSource = new JMenuItem(NbBundle.getMessage(Costanti.class, Costanti.LOAD_DATASOURCE_FOR_CHAIN));
    itemLoadDataSource.setActionCommand(LOAD);
    itemLoadDataSource.addActionListener(this);
    menu.add(itemLoadDataSource);
}

From source file:net.sf.mzmine.modules.visualization.twod.TwoDPlot.java

TwoDPlot(RawDataFile rawDataFile, TwoDVisualizerWindow visualizer, TwoDDataSet dataset, Range rtRange,
        Range mzRange) {/*from   w  w  w. j av a  2s.  c  o  m*/

    super(null, true);

    this.rawDataFile = rawDataFile;
    this.rtRange = rtRange;
    this.mzRange = mzRange;

    setBackground(Color.white);
    setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));

    // set the X axis (retention time) properties
    xAxis = new NumberAxis("Retention time");
    xAxis.setAutoRangeIncludesZero(false);
    xAxis.setNumberFormatOverride(rtFormat);
    xAxis.setUpperMargin(0);
    xAxis.setLowerMargin(0);

    // set the Y axis (intensity) properties
    yAxis = new NumberAxis("m/z");
    yAxis.setAutoRangeIncludesZero(false);
    yAxis.setNumberFormatOverride(mzFormat);
    yAxis.setUpperMargin(0);
    yAxis.setLowerMargin(0);

    // set the plot properties
    plot = new TwoDXYPlot(dataset, rtRange, mzRange, xAxis, yAxis);
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);

    // chart properties
    chart = new JFreeChart("", titleFont, plot, false);
    chart.setBackgroundPaint(Color.white);

    setChart(chart);

    // title
    chartTitle = chart.getTitle();
    chartTitle.setMargin(5, 0, 0, 0);
    chartTitle.setFont(titleFont);

    chartSubTitle = new TextTitle();
    chartSubTitle.setFont(subTitleFont);
    chartSubTitle.setMargin(5, 0, 0, 0);
    chart.addSubtitle(chartSubTitle);

    // disable maximum size (we don't want scaling)
    setMaximumDrawWidth(Integer.MAX_VALUE);
    setMaximumDrawHeight(Integer.MAX_VALUE);

    // set crosshair (selection) properties
    plot.setRangeCrosshairVisible(false);
    plot.setDomainCrosshairVisible(true);
    plot.setDomainCrosshairPaint(crossHairColor);
    plot.setDomainCrosshairStroke(crossHairStroke);

    // set rendering order
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    peakDataRenderer = new PeakDataRenderer();

    JMenuItem plotTypeMenuItem = new JMenuItem("Toggle centroid/continuous mode");
    plotTypeMenuItem.addActionListener(visualizer);
    plotTypeMenuItem.setActionCommand("SWITCH_PLOTMODE");
    add(plotTypeMenuItem);

    JPopupMenu popupMenu = getPopupMenu();
    popupMenu.addSeparator();
    popupMenu.add(plotTypeMenuItem);

}

From source file:de.atomfrede.tools.evalutation.ui.AppWindow.java

/**
 * Initialize the contents of the frame.
 *///from  w w w .  j a  va 2  s.c  om
private void initialize() {
    log.info("Plant Evaluator started");
    frame = new JFrame();

    frame.setIconImage(Icons.IC_APPLICATION_X_LARGE.getImage());

    AppWindow._frame = frame;
    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            if (reallyExit() == JOptionPane.YES_OPTION) {
                SingleInstance.release();
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            }
        }
    });

    frame.setTitle(Messages.getString("AppWindow.0") + " " + Messages.getString("AppWindow.version.code")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    frame.setLocationRelativeTo(null);
    JMenuBar menuBar = new JMenuBar();
    frame.setJMenuBar(menuBar);

    JMenu mnFile = new JMenu(Messages.getString("AppWindow.1")); //$NON-NLS-1$
    menuBar.add(mnFile);

    JMenuItem mntmExit = new JMenuItem(Messages.getString("AppWindow.3")); //$NON-NLS-1$
    mntmExit.setIcon(Icons.IC_LOGOUT_SMALL);
    mntmExit.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            WindowEvent wev = new WindowEvent(frame, WindowEvent.WINDOW_CLOSING);
            Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(wev);

        }
    });
    mnFile.add(mntmExit);

    JMenu mnEdit = new JMenu(Messages.getString("AppWindow.4")); //$NON-NLS-1$
    menuBar.add(mnEdit);

    JMenuItem mntmOptions = new JMenuItem(Messages.getString("AppWindow.5")); //$NON-NLS-1$
    mntmOptions.setIcon(Icons.IC_PREFERENCES_SYSTEM_SMALL);
    mntmOptions.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new OptionsDialog(frame);
        }
    });
    mnEdit.add(mntmOptions);

    JMenu mnTools = new JMenu(Messages.getString("AppWindow.mnTools.text")); //$NON-NLS-1$
    menuBar.add(mnTools);

    JMenuItem mntmPostprocessing = new JMenuItem(Messages.getString("AppWindow.mntmPostprocessing.text")); //$NON-NLS-1$
    mntmPostprocessing.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            // TODO Auto-generated method stub
        }
    });
    mnTools.add(mntmPostprocessing);

    JMenuItem mntmPlot = new JMenuItem(Messages.getString("AppWindow.mntmPlot.text")); //$NON-NLS-1$
    mntmPlot.setIcon(Icons.IC_TOOL_PLOT_SMALL);
    mntmPlot.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            DialogUtil.getInstance().showPlotTypeSelection();
        }
    });

    mnTools.add(mntmPlot);

    JMenu mnHelp = new JMenu(Messages.getString("AppWindow.6")); //$NON-NLS-1$
    menuBar.add(mnHelp);

    JMenuItem mntmAbout = new JMenuItem(Messages.getString("AppWindow.7")); //$NON-NLS-1$
    mntmAbout.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            try {
                new AboutDialog(frame);
            } catch (URISyntaxException e) {
                // TODO Auto-generated catch block

                e.printStackTrace();
            }
        }
    });
    mnHelp.add(mntmAbout);

    createContent();

    DialogUtil.getInstance().setMainFrame(frame);

}

From source file:de.codesourcery.eve.skills.ui.utils.PopupMenuBuilder.java

protected int populateMenu() {

    int itemCount = 0;
    for (Object obj : this.entries) {
        if (obj == SEPARATOR) {
            popupMenu.addSeparator();/* w  ww  .  ja  v a2s . com*/
        } else {
            final MyMenuItem item = (MyMenuItem) obj;

            final Action action = item.getAction();

            final boolean isEnabled = action.isEnabled();

            if (isEnabled || action instanceof IActionWithDisabledText) {
                final JMenuItem menuItem = new JMenuItem(action);

                final String text;
                if (isEnabled) {
                    text = item.getLabel();
                } else {
                    text = ((IActionWithDisabledText) action).getDisabledText();
                    // do not render action that returns a blank/empty label
                    if (StringUtils.isBlank(text)) {
                        continue;
                    }
                    menuItem.setEnabled(false);
                }
                menuItem.setText(text);
                popupMenu.add(menuItem);
                itemCount++;
            }
        }
    }
    return itemCount;
}

From source file:it.unibas.spicygui.controllo.provider.composition.MyPopupProviderConnectionChainComposition.java

private void createPopupMenu() {
    menu = new JPopupMenu("Popup menu");
    JMenuItem item;//from   w  w w .j ava 2 s. c om
    //        item = new JMenuItem(NbBundle.getMessage(Costanti.class, Costanti.SHOW_HIDE_INFO_CONNECTION));
    //        item.setActionCommand(SHOW);
    //        item.addActionListener(this);
    //        menu.add(item);

    //        itemConfidence = new JMenuItem();
    //        menu.add(itemConfidence);
    //
    //        itemImplied = new JCheckBoxMenuItem();
    //        menu.add(itemImplied);

    item = new JMenuItem(NbBundle.getMessage(Costanti.class, Costanti.DELETE_CONNECTION));
    item.setActionCommand(DELETE);
    item.addActionListener(this);
    menu.add(item);
}