Example usage for javax.swing JMenu add

List of usage examples for javax.swing JMenu add

Introduction

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

Prototype

public JMenuItem add(Action a) 

Source Link

Document

Creates a new menu item attached to the specified Action object and appends it to the end of this menu.

Usage

From source file:io.github.dsheirer.gui.SDRTrunk.java

/**
 * Initialize the contents of the frame.
 *//* w  w  w .  j  a va 2  s  .com*/
private void initGUI() {
    mMainGui.setLayout(new MigLayout("insets 0 0 0 0 ", "[grow,fill]", "[grow,fill]"));

    /**
     * Setup main JFrame window
     */
    mTitle = SystemProperties.getInstance().getApplicationName();
    mMainGui.setTitle(mTitle);
    mMainGui.setBounds(100, 100, 1280, 800);
    mMainGui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //Set preferred sizes to influence the split
    mSpectralPanel.setPreferredSize(new Dimension(1280, 300));
    mControllerPanel.setPreferredSize(new Dimension(1280, 500));

    mSplitPane = new JideSplitPane(JideSplitPane.VERTICAL_SPLIT);
    mSplitPane.setDividerSize(5);
    mSplitPane.add(mSpectralPanel);
    mSplitPane.add(mControllerPanel);

    mBroadcastStatusVisible = SystemProperties.getInstance().get(PROPERTY_BROADCAST_STATUS_VISIBLE, false);

    //Show broadcast status panel when user requests - disabled by default
    if (mBroadcastStatusVisible) {
        mSplitPane.add(getBroadcastStatusPanel());
    }

    mMainGui.add(mSplitPane, "cell 0 0,span,grow");

    /**
     * Menu items
     */
    JMenuBar menuBar = new JMenuBar();
    mMainGui.setJMenuBar(menuBar);

    JMenu fileMenu = new JMenu("File");
    menuBar.add(fileMenu);

    JMenuItem logFilesMenu = new JMenuItem("Logs & Recordings");
    logFilesMenu.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            try {
                Desktop.getDesktop().open(getHomePath().toFile());
            } catch (Exception e) {
                mLog.error("Couldn't open file explorer");

                JOptionPane.showMessageDialog(mMainGui,
                        "Can't launch file explorer - files are located at: " + getHomePath().toString(),
                        "Can't launch file explorer", JOptionPane.ERROR_MESSAGE);
            }
        }
    });
    fileMenu.add(logFilesMenu);

    JMenuItem settingsMenu = new JMenuItem("Icon Manager");
    settingsMenu.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            mIconManager.showEditor(mMainGui);
        }
    });
    fileMenu.add(settingsMenu);

    fileMenu.add(new JSeparator());

    JMenuItem exitMenu = new JMenuItem("Exit");
    exitMenu.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            System.exit(0);
        }
    });

    fileMenu.add(exitMenu);

    JMenu viewMenu = new JMenu("View");

    viewMenu.add(new BroadcastStatusVisibleMenuItem(mControllerPanel));

    menuBar.add(viewMenu);

    JMenuItem screenCaptureItem = new JMenuItem("Screen Capture");

    screenCaptureItem.setMnemonic(KeyEvent.VK_C);
    screenCaptureItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.ALT_MASK));

    screenCaptureItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            try {
                Robot robot = new Robot();

                final BufferedImage image = robot.createScreenCapture(mMainGui.getBounds());

                SystemProperties props = SystemProperties.getInstance();

                Path capturePath = props.getApplicationFolder("screen_captures");

                if (!Files.exists(capturePath)) {
                    try {
                        Files.createDirectory(capturePath);
                    } catch (IOException e) {
                        mLog.error("Couldn't create 'screen_captures' " + "subdirectory in the "
                                + "SDRTrunk application directory", e);
                    }
                }

                String filename = TimeStamp.getTimeStamp("_") + "_screen_capture.png";

                final Path captureFile = capturePath.resolve(filename);

                EventQueue.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            ImageIO.write(image, "png", captureFile.toFile());
                        } catch (IOException e) {
                            mLog.error("Couldn't write screen capture to " + "file [" + captureFile.toString()
                                    + "]", e);
                        }
                    }
                });
            } catch (AWTException e) {
                mLog.error("Exception while taking screen capture", e);
            }
        }
    });

    menuBar.add(screenCaptureItem);
}

From source file:com.googlecode.bpmn_simulator.gui.BPMNSimulatorFrame.java

private JMenu createMenuFile() {
    final JMenu menuFile = new JMenu(Messages.getString("Menu.file")); //$NON-NLS-1$

    final JMenuItem menuFileOpen = new JMenuItem(Messages.getString("Menu.fileOpen")); //$NON-NLS-1$
    menuFileOpen.setMnemonic(KeyEvent.VK_O);
    menuFileOpen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.ALT_MASK));
    menuFileOpen.addActionListener(new ActionListener() {
        @Override//from w  ww  .ja v  a  2 s  .  c  o  m
        public void actionPerformed(final ActionEvent e) {
            openFile();
        }
    });
    menuFile.add(menuFileOpen);
    menuFile.add(menuFileRecent);

    final JMenuItem menuFileReload = new JMenuItem(Messages.getString("Menu.fileReload")); //$NON-NLS-1$
    menuFileReload.setMnemonic(KeyEvent.VK_R);
    menuFileReload.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.ALT_MASK));
    menuFileReload.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            reloadDefinition();
        }
    });
    menuFile.add(menuFileReload);

    final JMenuItem menuFileClose = new JMenuItem(Messages.getString("Menu.fileClose")); //$NON-NLS-1$
    menuFileClose.setMnemonic(KeyEvent.VK_C);
    menuFileClose.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.ALT_MASK));
    menuFileClose.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            closeSource();
        }
    });
    menuFile.add(menuFileClose);

    menuFile.addSeparator();

    final JMenuItem menuFileProperties = new JMenuItem(Messages.getString("Menu.properties")); //$NON-NLS-1$
    menuFileProperties.setMnemonic(KeyEvent.VK_P);
    menuFileProperties.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.ALT_MASK));
    menuFileProperties.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            showPropertiesDialog();
        }
    });
    menuFile.add(menuFileProperties);

    menuFile.addSeparator();

    final JMenuItem menuFileExport = createMenuFileExport();
    menuFile.add(menuFileExport);

    menuFile.addSeparator();

    final JMenuItem menuFilePreferences = new JMenuItem(Messages.getString("Menu.preferences")); //$NON-NLS-1$
    menuFilePreferences.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            showPreferencesDialog();
        }
    });
    menuFile.add(menuFilePreferences);

    menuFile.addSeparator();

    final JMenuItem menuFileExit = new JMenuItem(Messages.getString("Menu.exit")); //$NON-NLS-1$
    menuFileExit.setMnemonic(KeyEvent.VK_E);
    menuFileExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.ALT_MASK));
    menuFileExit.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            for (Frame frame : getFrames()) {
                if (frame.isActive()) {
                    frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
                }
            }
        }
    });
    menuFile.add(menuFileExit);

    menuFile.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(final MenuEvent e) {
            menuFileReload.setEnabled(isSourceOpen() && currentSource.canReopen());
            menuFileClose.setEnabled(isSourceOpen());
            menuFileProperties.setEnabled(isDefinitionOpen());
            menuFileExport.setEnabled(isDefinitionOpen());
        }

        @Override
        public void menuDeselected(final MenuEvent e) {
        }

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

    return menuFile;
}

From source file:com.limegroup.gnutella.gui.library.LibraryTableMediator.java

private JMenu createAdvancedMenu(LibraryTableDataLine dl) {
    JMenu menu = new JMenu(GUIMediator.getStringResource("GENERAL_ADVANCED_SUB_MENU"));
    if (dl != null) {
        menu.add(new JMenuItem(LICENSE_ACTION));
        menu.add(new JMenuItem(BITZI_LOOKUP_ACTION));
        menu.add(new JMenuItem(MAGNET_LOOKUP_ACTION));
        menu.add(new JMenuItem(COPY_MAGNET_TO_CLIPBOARD_ACTION));
        File file = getFile(TABLE.getSelectedRow());
        menu.setEnabled(RouterService.getFileManager().isFileShared(file));
    }/* w ww  .  jav a 2  s  .  com*/

    if (menu.getItemCount() == 0)
        menu.setEnabled(false);

    return menu;
}

From source file:net.liuxuan.device.w3330.JIF_DrawChart_w3330.java

/**
 * ????/*from   w  w  w  . j  av  a 2  s  . co  m*/
 */
public void initChartMenu() {
    GetPointAction action = new GetPointAction();
    JMenu fx = new JMenu("?");
    JMenuItem jmenuitem_select1 = new JMenuItem("");
    jmenuitem_select1.addActionListener(action);
    fx.add(jmenuitem_select1);
    JMenuItem jmenuitem_select2 = new JMenuItem("");
    jmenuitem_select2.addActionListener(action);
    fx.add(jmenuitem_select2);
    JMenuItem jmenuitem_avg = new JMenuItem("?");
    jmenuitem_avg.addActionListener(action);
    fx.add(jmenuitem_avg);
    JMenuItem jmenuitem_parse = new JMenuItem("?");
    jmenuitem_parse.addActionListener(action);
    fx.add(jmenuitem_parse);
    JMenuItem jmenuitem_bzc = new JMenuItem("?");
    jmenuitem_bzc.addActionListener(action);
    fx.add(jmenuitem_bzc);

    JMenuItem jmenuitem_zz1 = new JMenuItem("1");
    jmenuitem_zz1.addActionListener(action);
    fx.add(jmenuitem_zz1);
    JMenuItem jmenuitem_zz2 = new JMenuItem("2");
    jmenuitem_zz2.addActionListener(action);
    fx.add(jmenuitem_zz2);
    chartPanel.getPopupMenu().add(fx);

    JMenu bx = new JMenu("");

    JMenuItem jmenuitem7 = new JMenuItem("");
    jmenuitem7.addActionListener(action);
    bx.add(jmenuitem7);
    JMenuItem jmenuitem9 = new JMenuItem("");
    jmenuitem9.addActionListener(action);
    bx.add(jmenuitem9);
    JMenuItem jmenuitem10 = new JMenuItem("");
    jmenuitem10.addActionListener(action);
    bx.add(jmenuitem10);

    chartPanel.getPopupMenu().add(bx);
}

From source file:be.ac.ua.comp.scarletnebula.gui.windows.GUI.java

private JMenu getServerMenu() {
    final JMenu serverMenu = new JMenu("Servers");
    serverMenu.setMnemonic(KeyEvent.VK_S);

    final JMenuItem startServerItem = new JMenuItem("Start new server", Utils.icon("add16.png"));
    startServerItem.setMnemonic(KeyEvent.VK_S);
    startServerItem.addActionListener(new ActionListener() {
        @Override//from w w  w. j  a va 2s  . c o m
        public void actionPerformed(final ActionEvent e) {
            startAddServerWizard();
        }
    });
    serverMenu.add(startServerItem);

    final JMenuItem searchServerItem = new JMenuItem("Filter servers", Utils.icon("search16.png"));
    searchServerItem.setMnemonic(KeyEvent.VK_F);
    searchServerItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            showFilter();
        }
    });
    serverMenu.add(searchServerItem);
    return serverMenu;
}

From source file:io.gameover.utilities.pixeleditor.Pixelizer.java

private JMenuBar getAppMenuBar() {
    if (this.appMenuBar == null) {
        this.appMenuBar = new JMenuBar();

        JMenu menuOpen = new JMenu("File");
        JMenuItem openMenu = new JMenuItem("Open...");
        openMenu.setActionCommand(ACTION_OPEN);
        InternalActionListener actionListener = new InternalActionListener(this);
        openMenu.addActionListener(actionListener);
        menuOpen.add(openMenu);

        JMenuItem saveMenuAsPng = new JMenuItem("Save as PNG...");
        saveMenuAsPng.setActionCommand(ACTION_SAVE_AS_PNG);
        saveMenuAsPng.addActionListener(actionListener);
        menuOpen.add(saveMenuAsPng);//from  ww  w .  java  2 s.  c  o m

        JMenuItem saveMenuAsGif = new JMenuItem("Save as GIF...");
        saveMenuAsGif.setActionCommand(ACTION_SAVE_AS_GIF);
        saveMenuAsGif.addActionListener(actionListener);
        menuOpen.add(saveMenuAsGif);

        this.appMenuBar.add(menuOpen);

        JMenu menuEdit = new JMenu("Edit");
        JMenuItem clearChangesMenu = new JMenuItem("Clear changes");
        clearChangesMenu.setActionCommand(ACTION_CLEAR);
        clearChangesMenu.addActionListener(actionListener);
        menuEdit.add(clearChangesMenu);
        JMenuItem clearSelectionMenu = new JMenuItem("Clear selection");
        clearSelectionMenu.setActionCommand(ACTION_CLEAR_SELECTION);
        clearSelectionMenu.addActionListener(actionListener);
        menuEdit.add(clearSelectionMenu);
        appMenuBar.add(menuEdit);
    }

    return appMenuBar;
}

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

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

/**
 * Creates a new instance of the help menu.
 *
 * @return the new help menu/*w w w  .j  ava2s.  c  o  m*/
 */
protected JMenu createHelpMenu() {
    JMenuItem menuItem;
    JMenu helpMenu = new JMenu("Help");
    helpMenu.setMnemonic(KeyEvent.VK_H);
    this.add(helpMenu);

    menuItem = new JMenuItem("Help Topics", KeyEvent.VK_H);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_H, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));

    try {
        URL hsURL = HelpSet.findHelpSet(this.getClass().getClassLoader(),
                "net/chaosserver/timelord/help/TimelordHelp.hs");
        HelpSet hs = new HelpSet(null, hsURL);
        HelpBroker hb = hs.createHelpBroker();
        menuItem.addActionListener(new CSH.DisplayHelpFromSource(hb));
    } catch (HelpSetException e) {
        menuItem.setEnabled(false);
    }

    // menuItem.setActionCommand(ACTION_ABOUT);
    helpMenu.add(menuItem);

    menuItem = new JMenuItem("Log Window");
    menuItem.setActionCommand(ACTION_LOG);
    menuItem.addActionListener(this);
    menuItem.setEnabled(false);
    helpMenu.add(menuItem);

    menuItem = new JMenuItem("Cause Memory Leak");
    menuItem.setActionCommand(ACTION_LEAK);
    menuItem.addActionListener(this);
    menuItem.setEnabled(false);
    helpMenu.add(menuItem);

    if (!OsUtil.isMac()) {
        helpMenu.addSeparator();

        menuItem = new JMenuItem("About Timelord", KeyEvent.VK_A);
        menuItem.setActionCommand(ACTION_ABOUT);
        menuItem.addActionListener(this);
        helpMenu.add(menuItem);
    }

    return helpMenu;
}

From source file:com.net2plan.gui.utils.viewEditTopolTables.specificTables.AdvancedJTable_multicastDemand.java

@Override
public void doPopup(final MouseEvent e, final int row, final Object itemId) {
    JPopupMenu popup = new JPopupMenu();
    final ITableRowFilter rf = callback.getVisualizationState().getTableRowFilter();
    final List<MulticastDemand> demandRowsInTheTable = getVisibleElementsInTable();

    /* Add the popup menu option of the filters */
    final List<MulticastDemand> selectedDemands = (List<MulticastDemand>) (List<?>) getSelectedElements()
            .getFirst();/*  w  w w .  jav a 2s.  co m*/
    if (!selectedDemands.isEmpty()) {
        final JMenu submenuFilters = new JMenu("Filters");
        final JMenuItem filterKeepElementsAffectedThisLayer = new JMenuItem(
                "This layer: Keep elements associated to this demand traffic");
        final JMenuItem filterKeepElementsAffectedAllLayers = new JMenuItem(
                "All layers: Keep elements associated to this demand traffic");
        submenuFilters.add(filterKeepElementsAffectedThisLayer);
        if (callback.getDesign().getNumberOfLayers() > 1)
            submenuFilters.add(filterKeepElementsAffectedAllLayers);
        filterKeepElementsAffectedThisLayer.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (selectedDemands.size() > 1)
                    throw new RuntimeException();
                TBFToFromCarriedTraffic filter = new TBFToFromCarriedTraffic(selectedDemands.get(0), true);
                callback.getVisualizationState().updateTableRowFilter(filter);
                callback.updateVisualizationJustTables();
            }
        });
        filterKeepElementsAffectedAllLayers.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (selectedDemands.size() > 1)
                    throw new RuntimeException();
                TBFToFromCarriedTraffic filter = new TBFToFromCarriedTraffic(selectedDemands.get(0), false);
                callback.getVisualizationState().updateTableRowFilter(filter);
                callback.updateVisualizationJustTables();
            }
        });
        popup.add(submenuFilters);
        popup.addSeparator();
    }

    if (callback.getVisualizationState().isNetPlanEditable()) {
        popup.add(getAddOption());
        for (JComponent item : getExtraAddOptions())
            popup.add(item);
    }

    if (!demandRowsInTheTable.isEmpty()) {
        if (callback.getVisualizationState().isNetPlanEditable()) {
            if (row != -1) {
                if (popup.getSubElements().length > 0)
                    popup.addSeparator();

                if (networkElementType == NetworkElementType.LAYER
                        && callback.getDesign().getNumberOfLayers() == 1) {

                } else {
                    JMenuItem removeItem = new JMenuItem("Remove " + networkElementType);

                    removeItem.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            NetPlan netPlan = callback.getDesign();

                            try {
                                netPlan.getMulticastDemandFromId((long) itemId).remove();
                                callback.getVisualizationState()
                                        .recomputeCanvasTopologyBecauseOfLinkOrNodeAdditionsOrRemovals();
                                callback.updateVisualizationAfterChanges(
                                        Collections.singleton(NetworkElementType.MULTICAST_DEMAND));
                                callback.getUndoRedoNavigationManager().addNetPlanChange();
                            } catch (Throwable ex) {
                                ErrorHandling.addErrorOrException(ex, getClass());
                                ErrorHandling.showErrorDialog("Unable to remove " + networkElementType);
                            }
                        }
                    });

                    popup.add(removeItem);
                }

                addPopupMenuAttributeOptions(e, row, itemId, popup);
            }
            if (networkElementType != NetworkElementType.LAYER) {
                JMenuItem removeItems = new JMenuItem("Remove all " + networkElementType + "s in table");

                removeItems.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        NetPlan netPlan = callback.getDesign();
                        try {
                            if (rf == null)
                                netPlan.removeAllMulticastDemands();
                            else
                                for (MulticastDemand d : demandRowsInTheTable)
                                    d.remove();
                            callback.getVisualizationState()
                                    .recomputeCanvasTopologyBecauseOfLinkOrNodeAdditionsOrRemovals();
                            callback.updateVisualizationAfterChanges(
                                    Collections.singleton(NetworkElementType.MULTICAST_DEMAND));
                            callback.getUndoRedoNavigationManager().addNetPlanChange();
                        } catch (Throwable ex) {
                            ex.printStackTrace();
                            ErrorHandling.showErrorDialog(ex.getMessage(),
                                    "Unable to remove all " + networkElementType + "s");
                        }
                    }
                });
                popup.add(removeItems);
            }

            List<JComponent> extraOptions = getExtraOptions(row, itemId);
            if (!extraOptions.isEmpty()) {
                if (popup.getSubElements().length > 0)
                    popup.addSeparator();
                for (JComponent item : extraOptions)
                    popup.add(item);
            }
        }

        List<JComponent> forcedOptions = getForcedOptions();
        if (!forcedOptions.isEmpty()) {
            if (popup.getSubElements().length > 0)
                popup.addSeparator();
            for (JComponent item : forcedOptions)
                popup.add(item);
        }
    }

    popup.show(e.getComponent(), e.getX(), e.getY());
}

From source file:fll.scheduler.SchedulerUI.java

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

    menu.add(mPreferencesAction);
    menu.add(mExitAction);/*w  ww .  j av  a 2 s.  c om*/

    return menu;
}