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:components.MenuLookDemo.java

public JMenuBar createMenuBar() {
    JMenuBar menuBar;//from   w w  w  . j  av a2 s .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:MenuLookDemo.java

public JMenuBar createMenuBar() {
    JMenuBar menuBar;//from w  w  w . j  a  v a 2  s. co 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:org.angnysa.yaba.swing.BudgetFrame.java

private void buildMenubar() {
    JMenuBar menuBar = new JMenuBar();
    JMenu fileMenu = new JMenu(Messages.getString("menu.file.label")); //$NON-NLS-1$
    JMenuItem item;// w  w  w.j  a v  a 2  s  .c om

    // new
    item = new JMenuItem(Messages.getString("menu.file.new")); //$NON-NLS-1$
    item.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            SwingMain.newEditor(null);
        }
    });
    fileMenu.add(item);

    // open
    item = new JMenuItem(Messages.getString("menu.file.open")); //$NON-NLS-1$
    item.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            SwingMain.open(id);
        }
    });
    fileMenu.add(item);

    // save
    item = new JMenuItem(Messages.getString("menu.file.save")); //$NON-NLS-1$
    item.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            SwingMain.save(id);
        }
    });
    fileMenu.add(item);

    // save as
    item = new JMenuItem(Messages.getString("menu.file.save-as")); //$NON-NLS-1$
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            SwingMain.saveas(id);
        }
    });
    fileMenu.add(item);

    // close
    item = new JMenuItem(Messages.getString("menu.file.close")); //$NON-NLS-1$
    item.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_W, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            SwingMain.close(id);
        }
    });
    fileMenu.add(item);

    menuBar.add(fileMenu);
    setJMenuBar(menuBar);
}

From source file:TableRowColumnTest.java

public PlanetTableFrame() {
    setTitle("TableRowColumnTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    TableModel model = new DefaultTableModel(cells, columnNames) {
        public Class<?> getColumnClass(int c) {
            return cells[0][c].getClass();
        }//from  ww  w.j a v  a2s. c o  m
    };

    table = new JTable(model);

    table.setRowHeight(100);
    table.getColumnModel().getColumn(COLOR_COLUMN).setMinWidth(250);
    table.getColumnModel().getColumn(IMAGE_COLUMN).setMinWidth(100);

    final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);
    table.setRowSorter(sorter);
    sorter.setComparator(COLOR_COLUMN, new Comparator<Color>() {
        public int compare(Color c1, Color c2) {
            int d = c1.getBlue() - c2.getBlue();
            if (d != 0)
                return d;
            d = c1.getGreen() - c2.getGreen();
            if (d != 0)
                return d;
            return c1.getRed() - c2.getRed();
        }
    });
    sorter.setSortable(IMAGE_COLUMN, false);
    add(new JScrollPane(table), BorderLayout.CENTER);

    removedRowIndices = new HashSet<Integer>();
    removedColumns = new ArrayList<TableColumn>();

    final RowFilter<TableModel, Integer> filter = new RowFilter<TableModel, Integer>() {
        public boolean include(Entry<? extends TableModel, ? extends Integer> entry) {
            return !removedRowIndices.contains(entry.getIdentifier());
        }
    };

    // create menu

    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    JMenu selectionMenu = new JMenu("Selection");
    menuBar.add(selectionMenu);

    rowsItem = new JCheckBoxMenuItem("Rows");
    columnsItem = new JCheckBoxMenuItem("Columns");
    cellsItem = new JCheckBoxMenuItem("Cells");

    rowsItem.setSelected(table.getRowSelectionAllowed());
    columnsItem.setSelected(table.getColumnSelectionAllowed());
    cellsItem.setSelected(table.getCellSelectionEnabled());

    rowsItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            table.clearSelection();
            table.setRowSelectionAllowed(rowsItem.isSelected());
            updateCheckboxMenuItems();
        }
    });
    selectionMenu.add(rowsItem);

    columnsItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            table.clearSelection();
            table.setColumnSelectionAllowed(columnsItem.isSelected());
            updateCheckboxMenuItems();
        }
    });
    selectionMenu.add(columnsItem);

    cellsItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            table.clearSelection();
            table.setCellSelectionEnabled(cellsItem.isSelected());
            updateCheckboxMenuItems();
        }
    });
    selectionMenu.add(cellsItem);

    JMenu tableMenu = new JMenu("Edit");
    menuBar.add(tableMenu);

    JMenuItem hideColumnsItem = new JMenuItem("Hide Columns");
    hideColumnsItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            int[] selected = table.getSelectedColumns();
            TableColumnModel columnModel = table.getColumnModel();

            // remove columns from view, starting at the last
            // index so that column numbers aren't affected

            for (int i = selected.length - 1; i >= 0; i--) {
                TableColumn column = columnModel.getColumn(selected[i]);
                table.removeColumn(column);

                // store removed columns for "show columns" command

                removedColumns.add(column);
            }
        }
    });
    tableMenu.add(hideColumnsItem);

    JMenuItem showColumnsItem = new JMenuItem("Show Columns");
    showColumnsItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            // restore all removed columns
            for (TableColumn tc : removedColumns)
                table.addColumn(tc);
            removedColumns.clear();
        }
    });
    tableMenu.add(showColumnsItem);

    JMenuItem hideRowsItem = new JMenuItem("Hide Rows");
    hideRowsItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            int[] selected = table.getSelectedRows();
            for (int i : selected)
                removedRowIndices.add(table.convertRowIndexToModel(i));
            sorter.setRowFilter(filter);
        }
    });
    tableMenu.add(hideRowsItem);

    JMenuItem showRowsItem = new JMenuItem("Show Rows");
    showRowsItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            removedRowIndices.clear();
            sorter.setRowFilter(filter);
        }
    });
    tableMenu.add(showRowsItem);

    JMenuItem printSelectionItem = new JMenuItem("Print Selection");
    printSelectionItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            int[] selected = table.getSelectedRows();
            System.out.println("Selected rows: " + Arrays.toString(selected));
            selected = table.getSelectedColumns();
            System.out.println("Selected columns: " + Arrays.toString(selected));
        }
    });
    tableMenu.add(printSelectionItem);
}

From source file:com.mightypocket.ashot.Mediator.java

private JMenuBar createMenuBar() {
    BindingGroup menuBinding = new BindingGroup();
    ResourceMap resourceMap = application.getContext().getResourceMap(Mediator.class);
    ApplicationActionMap actionMap = getActionMap();
    JMenuBar bar = new JMenuBar();

    // Menu File//ww w  .  j a  v  a2s . c  o m
    JMenu menuFile = new JMenu(resourceMap.getString("menu.file"));
    menuFileDevices = new JMenu(resourceMap.getString("menu.file.devices.text"));
    menuFileDevices.setIcon(resourceMap.getIcon("menu.file.devices.icon"));
    menuFile.add(menuFileDevices);
    menuBinding.addBinding(bindRead(this, PROP_DEVICES, menuFileDevices, "enabled"));
    menuFile.addSeparator();
    menuFile.add(new JMenuItem(actionMap.get(ACTION_SAVE_SCREENSHOT)));
    menuFile.add(new JCheckBoxMenuItem(actionMap.get(ACTION_RECORDING)));
    menuFile.add(new JMenuItem(actionMap.get(ACTION_OPEN_DESTINATION_FOLDER)));
    menuFile.addSeparator();
    menuFile.add(new JMenuItem(actionMap.get(ACTION_CHANGE_DEFAULT_FOLDER)));
    menuFile.add(new JMenuItem(actionMap.get(ACTION_CHANGE_SDK_FOLDER)));
    menuFile.addSeparator();
    menuFile.add(new JMenuItem(actionMap.get("quit")));

    // Menu Edit
    JMenu menuEdit = new JMenu(resourceMap.getString("menu.edit"));
    menuEdit.add(new JMenuItem(actionMap.get(ACTION_COPY_TO_CLIPBOARD)));

    // Menu View
    JMenu menuView = new JMenu(resourceMap.getString("menu.view"));
    menuView.add(new JCheckBoxMenuItem(actionMap.get(ACTION_SHOW_TOOLBAR_LABELS)));
    menuView.addSeparator();
    menuView.add(new JCheckBoxMenuItem(actionMap.get(ACTION_LANDSCAPE)));
    menuView.add(new JCheckBoxMenuItem(actionMap.get(ACTION_LANDSCAPE_CW)));
    menuView.addSeparator();
    menuView.add(new JMenuItem(actionMap.get(ACTION_ZOOM_IN)));
    menuView.add(new JMenuItem(actionMap.get(ACTION_ZOOM_OUT)));
    menuView.add(new JMenuItem(actionMap.get(ACTION_SIZE_ORIGINAL)));
    menuView.add(new JMenuItem(actionMap.get(ACTION_SIZE_SMALL)));
    menuView.add(new JMenuItem(actionMap.get(ACTION_SIZE_LARGE)));
    menuView.add(new JCheckBoxMenuItem(actionMap.get(ACTION_SIZE_FIT)));
    menuView.addSeparator();
    menuView.add(new JMenuItem(actionMap.get(ACTION_FULL_SCREEN)));

    // Menu Tools
    JMenu toolsView = new JMenu(resourceMap.getString("menu.tools"));
    toolsView.add(new JMenuItem(actionMap.get(ACTION_INSTALL)));
    toolsView.addSeparator();
    toolsView.add(new JMenuItem(actionMap.get(ACTION_OPTIONS)));

    // Menu Help
    JMenu menuHelp = new JMenu(resourceMap.getString("menu.help"));
    menuHelp.add(new JMenuItem(actionMap.get(ACTION_CHECK_UPDATES)));
    menuHelp.add(new JMenuItem(actionMap.get(ACTION_ABOUT)));

    bar.add(menuFile);
    bar.add(menuEdit);
    bar.add(menuView);
    bar.add(toolsView);
    bar.add(menuHelp);

    menuBinding.bind();

    return bar;
}

From source file:com.moss.bdbadmin.client.ui.BdbAdminClient.java

public BdbAdminClient(HttpClient httpClient, JFrame window, File configPath, ProxyFactory proxyFactory) {

    this.httpClient = httpClient;
    this.ancestor = window;
    this.configPath = configPath;
    this.proxyFactory = proxyFactory;

    try {//from   w w w . j a v a2  s.  co m
        configJaxbContext = JAXBContext.newInstance(ServiceConfig.class);
    } catch (JAXBException ex) {
        throw new RuntimeException(ex);
    }

    JMenuItem newServiceItem = new JMenuItem("New Service");
    newServiceItem.setAction(new NewServiceAction());

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

    JMenuBar menuBar = new JMenuBar();
    menuBar.add(fileMenu);

    window.setJMenuBar(menuBar);
    window.setIconImage(new ImageIcon(this.getClass().getClassLoader().getResource("service.gif")).getImage());

    this.root = new DefaultMutableTreeNode();
    this.model = new DefaultTreeModel(root);
    getTree().setModel(model);
    getTree().setShowsRootHandles(true);
    getTree().setRootVisible(false);
    getTree().setCellRenderer(new Renderer());
    getTree().getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    getTree().getSelectionModel().addTreeSelectionListener(new SelectionListener());
    getTree().addMouseListener(new ContextMenuHandler());

    addAncestorListener(new AncestorListener() {
        public void ancestorAdded(AncestorEvent event) {
            loadConfig();
        }

        public void ancestorMoved(AncestorEvent event) {
        }

        public void ancestorRemoved(AncestorEvent event) {
        }
    });
}

From source file:org.griphyn.vdl.karajan.monitor.monitors.swing.GraphPanel.java

protected void displayAddPopup(JButton src) {
    JPopupMenu p = new JPopupMenu();

    Map<String, List<Series<?>>> series = sampler.getCategories();

    for (Map.Entry<String, List<Series<?>>> e1 : series.entrySet()) {
        JMenu sm = new JMenu(e1.getKey());
        for (final Series<?> s : e1.getValue()) {
            if (!enabled.contains(s.getKey())) {
                JMenuItem mi = new JMenuItem(s.getLabel());

                mi.addActionListener(new ActionListener() {
                    @Override//from  w  ww .ja  v  a2  s  .  co  m
                    public void actionPerformed(ActionEvent e) {
                        enable(s);
                    }
                });
                sm.add(mi);
            }
        }
        p.add(sm);
    }

    p.show(src, 4, 4);
}

From source file:coolmap.application.widget.impl.WidgetUserGroup.java

private void initPopup() {
    JPopupMenu popup = new JPopupMenu();
    table.setComponentPopupMenu(popup);//from www  .j  a va  2 s  .  c  o  m

    JMenuItem item = new JMenuItem("Rename");
    popup.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            List<String> groupNames = getSelectedGroups();
            if (groupNames.isEmpty()) {
                return;
            }

            String returnVal = JOptionPane.showInputDialog(CoolMapMaster.getCMainFrame(),
                    "Please provide a new name:");
            if (returnVal == null || returnVal.length() == 0) {
                returnVal = "Untitled";
            }

            int counter = 0;
            String newName;
            for (String groupName : groupNames) {
                if (counter == 0) {
                    newName = returnVal;
                } else {
                    newName = returnVal + "_" + counter;
                }

                //new name must not exist
                int subCounter = 0;
                String name = newName;
                while (nodeGroups.containsKey(name)) {
                    subCounter++;
                    name = newName + "_" + subCounter;
                }
                newName = name;

                Color c = nodeColor.get(groupName);
                Set<VNode> nodes = new HashSet(nodeGroups.get(groupName));

                nodeColor.remove(groupName);
                nodeGroups.removeAll(groupName);

                nodeColor.put(newName, c);
                nodeGroups.putAll(newName, nodes);

                //                    System.out.println(newName + " " + c + " " + nodes);
                counter++;
            }

            updateTable();

        }
    });
    ////////////////////////////////////////////////////////////////////////

    //remove operations
    item = new JMenuItem("Remove");
    popup.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            List<String> groupNames = getSelectedGroups();
            for (String group : groupNames) {
                nodeColor.remove(group);
                nodeGroups.removeAll(group);
            }
            updateTable();
        }
    });

    //add separarator
    popup.addSeparator();
    JMenu insertRow = new JMenu("Add selected to row");
    popup.add(insertRow);

    JMenu insertColumn = new JMenu("Add selected to column");
    popup.add(insertColumn);

    item = new JMenuItem("prepend", UI.getImageIcon("prependRow"));
    insertRow.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            insertRow(0);
        }
    });

    item = new JMenuItem("prepend", UI.getImageIcon("prependColumn"));
    insertColumn.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            insertColumn(0);
        }
    });

    item = new JMenuItem("insert", UI.getImageIcon("insertRow"));
    item.setToolTipText("Insert selected groups to the selected region in the active coolmap view");
    insertRow.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            CoolMapObject obj = CoolMapMaster.getActiveCoolMapObject();
            if (obj == null) {
                return;
            }

            int index = 0;
            ArrayList selectedRows = obj.getCoolMapView().getSelectedRows();
            if (!selectedRows.isEmpty()) {
                index = ((Range<Integer>) selectedRows.iterator().next()).lowerEndpoint();
            }
            insertRow(index);
        }
    });

    item = new JMenuItem("insert", UI.getImageIcon("insertColumn"));
    item.setToolTipText("Insert selected groups to the selected region in the active coolmap view");
    insertColumn.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            CoolMapObject obj = CoolMapMaster.getActiveCoolMapObject();
            if (obj == null) {
                return;
            }

            int index = 0;
            ArrayList selectedColumns = obj.getCoolMapView().getSelectedColumns();
            if (!selectedColumns.isEmpty()) {
                index = ((Range<Integer>) selectedColumns.iterator().next()).lowerEndpoint();
            }
            insertColumn(index);
        }
    });

    item = new JMenuItem("append", UI.getImageIcon("appendRow"));
    insertRow.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (CoolMapMaster.getActiveCoolMapObject() == null) {
                return;
            }
            insertRow(CoolMapMaster.getActiveCoolMapObject().getViewNumRows());
        }
    });

    item = new JMenuItem("append", UI.getImageIcon("appendColumn"));
    insertColumn.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (CoolMapMaster.getActiveCoolMapObject() == null) {
                return;
            }
            insertColumn(CoolMapMaster.getActiveCoolMapObject().getViewNumColumns());
        }
    });

    item = new JMenuItem("replace", UI.getImageIcon("replaceRow"));
    insertRow.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            replaceRow();
        }
    });

    item = new JMenuItem("replace", UI.getImageIcon("replaceColumn"));
    insertColumn.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            replaceColumn();
        }
    });
}

From source file:gdt.jgui.base.JPropertyPanel.java

/**
 * Get context menu. /*from w  ww . j  av a2s .  c o  m*/
 * @return context menu..
 */
@Override
public JMenu getContextMenu() {
    JMenu menu = new JMenu("Context");
    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");
                    JConsoleHandler.execute(console, responseLocator$);
                } catch (Exception ee) {
                    LOGGER.severe(ee.toString());
                }
            } else
                console.back();
        }
    });
    menu.add(doneItem);
    return menu;
}

From source file:components.MenuDemo.java

public JMenuBar createMenuBar() {
    JMenuBar menuBar;//w  ww .j  av a  2 s  . co 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);

    return menuBar;
}