Example usage for javax.swing JMenu JMenu

List of usage examples for javax.swing JMenu JMenu

Introduction

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

Prototype

public JMenu(Action a) 

Source Link

Document

Constructs a menu whose properties are taken from the Action supplied.

Usage

From source file:coreferenceresolver.gui.MarkupGUI.java

public MarkupGUI() throws IOException {
    highlightPainters = new ArrayList<>();

    for (int i = 0; i < COLORS.length; ++i) {
        DefaultHighlighter.DefaultHighlightPainter highlightPainter = new DefaultHighlighter.DefaultHighlightPainter(
                COLORS[i]);//w w w.j a  v  a 2  s. c o m
        highlightPainters.add(highlightPainter);
    }

    defaulPath = FileUtils.readFileToString(new File(".\\src\\coreferenceresolver\\gui\\defaultpath"));
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setLayout(new BorderLayout());
    this.setSize(java.awt.Toolkit.getDefaultToolkit().getScreenSize());

    JMenuBar menuBar = new JMenuBar();
    JMenu fileMenu = new JMenu("File");
    //create menu items
    JMenuItem importMenuItem = new JMenuItem("Import");

    JMenuItem exportMenuItem = new JMenuItem("Export");

    fileMenu.add(importMenuItem);
    fileMenu.add(exportMenuItem);

    menuBar.add(fileMenu);

    this.setJMenuBar(menuBar);

    ScrollablePanel mainPanel = new ScrollablePanel();
    mainPanel.setScrollableWidth(ScrollablePanel.ScrollableSizeHint.NONE);
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));

    //IMPORT BUTTON
    importMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //                MarkupGUI.reviewElements.clear();
            //                MarkupGUI.markupReviews.clear();                
            JFileChooser markupFileChooser = new JFileChooser(defaulPath);
            markupFileChooser.setDialogTitle("Choose your markup file");
            markupFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

            if (markupFileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
                final JDialog d = new JDialog();
                JPanel p1 = new JPanel(new GridBagLayout());
                p1.add(new JLabel("Please Wait..."), new GridBagConstraints());
                d.getContentPane().add(p1);
                d.setSize(100, 100);
                d.setLocationRelativeTo(null);
                d.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
                d.setModal(true);

                SwingWorker<?, ?> worker = new SwingWorker<Void, Void>() {
                    protected Void doInBackground() throws IOException, BadLocationException {
                        readMarkupFile(markupFileChooser.getSelectedFile().getAbsolutePath());
                        for (int i = 0; i < markupReviews.size(); ++i) {
                            mainPanel.add(newReviewPanel(markupReviews.get(i), i));
                        }
                        return null;
                    }

                    protected void done() {
                        MarkupGUI.this.revalidate();
                        d.dispose();
                    }
                };
                worker.execute();
                d.setVisible(true);
            } else {
                return;
            }
        }
    });

    //EXPORT BUTTON: GET NEW VALUE (REF, TYPE) OF NPs      
    exportMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser markupFileChooser = new JFileChooser(defaulPath);
            markupFileChooser.setDialogTitle("Choose where your markup file saved");
            markupFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

            if (markupFileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
                final JDialog d = new JDialog();
                JPanel p1 = new JPanel(new GridBagLayout());
                p1.add(new JLabel("Please Wait..."), new GridBagConstraints());
                d.getContentPane().add(p1);
                d.setSize(100, 100);
                d.setLocationRelativeTo(null);
                d.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
                d.setModal(true);

                SwingWorker<?, ?> worker = new SwingWorker<Void, Void>() {
                    protected Void doInBackground() throws IOException {
                        for (Review review : markupReviews) {
                            generateNPsRef(review);
                        }
                        int i = 0;
                        for (ReviewElement reviewElement : reviewElements) {
                            int j = 0;
                            for (Element element : reviewElement.elements) {
                                String newType = element.typeSpinner.getValue().toString();
                                if (newType.equals("Object")) {
                                    markupReviews.get(i).getNounPhrases().get(j).setType(0);
                                } else if (newType.equals("Attribute")) {
                                    markupReviews.get(i).getNounPhrases().get(j).setType(3);
                                } else if (newType.equals("Other")) {
                                    markupReviews.get(i).getNounPhrases().get(j).setType(1);
                                } else if (newType.equals("Candidate")) {
                                    markupReviews.get(i).getNounPhrases().get(j).setType(2);
                                }
                                ++j;
                            }
                            ++i;
                        }
                        initMarkupFile(markupFileChooser.getSelectedFile().getAbsolutePath() + File.separator
                                + "markup.out.txt");
                        return null;
                    }

                    protected void done() {
                        d.dispose();
                        try {
                            Desktop.getDesktop()
                                    .open(new File(markupFileChooser.getSelectedFile().getAbsolutePath()));
                        } catch (IOException ex) {
                            Logger.getLogger(MarkupGUI.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                };
                worker.execute();
                d.setVisible(true);
            } else {
                return;
            }
        }
    });

    JScrollPane scrollMainPane = new JScrollPane(mainPanel);
    scrollMainPane.getVerticalScrollBar().setUnitIncrement(16);
    scrollMainPane.setPreferredSize(new Dimension(this.getWidth(), this.getHeight()));
    scrollMainPane.setSize(this.getWidth(), this.getHeight());
    this.setResizable(false);
    this.add(scrollMainPane, BorderLayout.CENTER);
    this.setExtendedState(JFrame.MAXIMIZED_BOTH);
    this.pack();
}

From source file:net.sf.clichart.main.ChartFrame.java

private void createMenu() {
    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);// w w  w  .  java2  s  .c  o  m

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

    JMenuItem saveItem = new JMenuItem("Save as...", KeyEvent.VK_S);
    saveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
    saveItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            saveChart();
        }
    });
    fileMenu.add(saveItem);

    JMenuItem exitItem = new JMenuItem("Exit", KeyEvent.VK_Q);
    exitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
    exitItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });
    fileMenu.addSeparator();
    fileMenu.add(exitItem);

}

From source file:uk.co.petertribble.jkstat.gui.KstatBaseChartFrame.java

/**
 * Create the Sleep for... Menu./* w w  w . j a  va2s  .co  m*/
 *
 * @return the Sleep Menu
 */
protected JMenu sleepMenu() {
    JMenu jms = new JMenu(KstatResources.getString("SLEEP.TEXT"));
    jms.setMnemonic(KeyEvent.VK_U);
    sleepItem1 = new JRadioButtonMenuItem(KstatResources.getString("SLEEP.1"));
    sleepItem1.addActionListener(this);
    sleepItem2 = new JRadioButtonMenuItem(KstatResources.getString("SLEEP.2"));
    sleepItem2.addActionListener(this);
    sleepItem5 = new JRadioButtonMenuItem(KstatResources.getString("SLEEP.5"), true);
    sleepItem5.addActionListener(this);
    sleepItem10 = new JRadioButtonMenuItem(KstatResources.getString("SLEEP.10"));
    sleepItem10.addActionListener(this);
    jms.add(sleepItem1);
    jms.add(sleepItem2);
    jms.add(sleepItem5);
    jms.add(sleepItem10);

    ButtonGroup sleepGroup = new ButtonGroup();
    sleepGroup.add(sleepItem1);
    sleepGroup.add(sleepItem2);
    sleepGroup.add(sleepItem5);
    sleepGroup.add(sleepItem10);

    return jms;
}

From source file:ActionExampleSwing.java

public ActionExampleSwing() {
    super("ActionExample Swing");

    setChannel(currentChannel); // enable/disable the Actions as appropriate

    channelLabel.setHorizontalAlignment(JLabel.CENTER);
    channelLabel.setFont(new Font("Serif", Font.PLAIN, 32));

    getContentPane().add(channelLabel, BorderLayout.NORTH);

    JPanel buttonPanel = new JPanel(new GridLayout(2, 2, 16, 6));
    buttonPanel.setBorder(BorderFactory.createEmptyBorder(6, 16, 16, 16));
    getContentPane().add(buttonPanel, BorderLayout.CENTER);
    buttonPanel.add(new JButton(upAction));
    buttonPanel.add(new JButton(gotoFavoriteAction));
    buttonPanel.add(new JButton(downAction));
    buttonPanel.add(new JButton(setFavoriteAction));

    JMenuBar mb = new JMenuBar();
    JMenu menu = new JMenu("Channel");
    menu.add(new JMenuItem(upAction));
    menu.add(new JMenuItem(downAction));
    menu.addSeparator();//from   w  w  w.j  ava2  s  . c o m
    menu.add(new JMenuItem(gotoFavoriteAction));
    menu.add(new JMenuItem(setFavoriteAction));
    mb.add(menu);
    setJMenuBar(mb);
}

From source file:com.apatar.ui.Actions.java

private void createMenubar() {

    menubar = new JMenuBar();

    JMenu fileMenu = new JMenu("File");
    fileMenu.add(newPrj);//from  ww w  .j a v a  2s  . c o  m

    fileMenu.add(open);
    fileMenu.addSeparator();
    fileMenu.add(save);
    fileMenu.add(saveAs);
    fileMenu.addSeparator();
    // fileMenu.add(publishToApatar);@@
    // fileMenu.add(runScheduling);@@
    // fileMenu.addSeparator();@@
    fileMenu.add(run);
    // fileMenu.addSeparator();
    // apon
    // fileMenu.add(newWebService);@@
    // fileMenu.addSeparator();@@

    // fileMenu.add(options);@@
    // fileMenu.addSeparator();@@
    fileMenu.add(exit);

    // JMenu viewMenu = new JMenu("View");//@@
    // viewMenu.add(windowsLookAndFeel);//@@
    // viewMenu.add(metalLookAndFeel); //@@
    // viewMenu.add(motifLookAndFeel); //@@

    // JMenu debugMenu = new JMenu("Debug");//@@
    // debugMenu.add(debugOutput);//@@
    // debugMenu.add(errorOutput);//@@

    // JMenu communityMenu = new JMenu("Community");//@@
    // communityMenu.add(catalogOfApatars);//@@
    // communityMenu.add(demos);//@@
    // communityMenu.add(forums);//@@
    // communityMenu.add(wiki);//@@

    /*
     * @@ JMenu helpMenu = new JMenu("Help"); helpMenu.add(about);
     * helpMenu.addSeparator(); helpMenu.add(featureRequest);
     * helpMenu.add(submitBug); helpMenu.add(tutorials);
     */
    menubar.add(fileMenu);
    // menubar.add(viewMenu);//@@
    // menubar.add(debugMenu);//@@
    // menubar.add(communityMenu);//@@
    // menubar.add(helpMenu);//@@
}

From source file:unikn.dbis.univis.visualization.graph.plaf.VGraphUI.java

/**
 * Creates the listener responsible for calling the correct handlers based
 * on mouse events, and to select invidual cells.
 *//*w  w  w . j av  a2 s . c o m*/
protected MouseListener createMouseListener() {

    return new MouseHandler() {

        /**
         * Invoked when a mouse button has been pressed on a component.
         *
         //@Override
         public void mousePressed(MouseEvent e) {
                
         Object o = graph.getFirstCellForLocation(e.getX(), e.getY());
                
         if (o instanceof VGraphCell) {
                
         VGraphCell cell = (VGraphCell) o;
                
         JPopupMenu menu = new JPopupMenu();
                
         VChartPanel chartPanel = (VChartPanel) cell.getUserObject();
                
         if (chartPanel.isShowPopUp()) {
                
         LegendItemCollection collect = chartPanel.getChart().getPlot().getLegendItems();
         JMenu first = new JMenu("1-39");
         int checker = 0;
                
         for (Iterator iter = collect.iterator(); iter.hasNext();) {
         LegendItem item = (LegendItem) iter.next();
         checker++;
         first.add(new JMenuItem(item.getLabel()));
         if ((checker % 40) == 0) {
         menu.add(first);
                
         first = new JMenu("" + checker + "-" + (checker + 39));
         }
         if (!iter.hasNext()) {
         menu.add(first);
         }
         }
                
         menu.show(graph, e.getX(), e.getY());
         }
         }
                
         super.mousePressed(e);
         }
         */

        /**
         * Invoked when a mouse button has been pressed on a component.
         */
        @Override
        public void mousePressed(MouseEvent e) {

            Object o = graph.getFirstCellForLocation(e.getX(), e.getY());

            if (SwingUtilities.isLeftMouseButton(e) && e.isAltDown()) {
                if (o instanceof VGraphCell) {

                    VGraphCell cell = (VGraphCell) o;

                    JPopupMenu menu = new JPopupMenu();

                    VChartPanel chartPanel = (VChartPanel) cell.getUserObject();

                    LegendItemCollection collect = chartPanel.getChart().getPlot().getLegendItems();
                    JMenu first = new JMenu("1-39");
                    int checker = 0;

                    for (Iterator iter = collect.iterator(); iter.hasNext();) {
                        LegendItem item = (LegendItem) iter.next();
                        checker++;
                        first.add(new JMenuItem(item.getLabel()));
                        if ((checker % 40) == 0) {
                            menu.add(first);

                            first = new JMenu("" + checker + "-" + (checker + 39));
                        }
                        if (!iter.hasNext()) {
                            menu.add(first);
                        }
                    }

                    menu.show(graph, e.getX(), e.getY());
                }
            }

            super.mousePressed(e);

            if (o != null && o instanceof VGraphCell) {

                VGraphCell cell = (VGraphCell) o;

                o = cell.getUserObject();

                if (o != null && o instanceof VChartPanel) {
                    VChartPanel chart = (VChartPanel) o;

                    for (MouseListener l : chart.getMouseListeners()) {
                        l.mousePressed(e);
                    }
                }
            }
        }

        // Event may be null when called to cancel the current operation.
        @Override
        public void mouseReleased(MouseEvent e) {
            super.mouseReleased(e);

            Object o = graph.getFirstCellForLocation(e.getX(), e.getY());

            if (o != null && o instanceof VGraphCell) {

                VGraphCell cell = (VGraphCell) o;

                o = cell.getUserObject();

                if (o != null && o instanceof VChartPanel) {
                    VChartPanel chart = (VChartPanel) o;

                    for (MouseListener l : chart.getMouseListeners()) {
                        l.mouseReleased(e);
                    }
                }
            }
        }

        /**
         * Invoked when the mouse has been clicked on a component.
         */
        @Override
        public void mouseClicked(MouseEvent e) {
            super.mouseClicked(e);

            Object o = graph.getFirstCellForLocation(e.getX(), e.getY());

            if (o != null && o instanceof VGraphCell) {

                VGraphCell cell = (VGraphCell) o;

                o = cell.getUserObject();

                if (o != null && o instanceof VChartPanel) {
                    VChartPanel chart = (VChartPanel) o;

                    if (SwingUtilities.isRightMouseButton(e)) {
                        JPopupMenu menu = chart.createPopupMenu(true, true, true, true);

                        menu.show(graph, e.getX(), e.getY());
                    }

                    /*
                    for (MouseListener l : chart.getMouseListeners()) {
                    System.out.println("LISTENS CLI");
                    l.mouseClicked(e);
                    }
                    */
                }
            }
        }

        /*
        // Event may be null when called to cancel the current operation.
        @Override
        public void mouseReleased(MouseEvent e) {
        super.mouseReleased(e);
                
        Object[] cells = graphSelectionModel.getSelectionCells();
                
        Rectangle2D bounds = graph.getCellBounds(cells);
                
        if (bounds != null) {
            Rectangle2D b2 = graph.toScreen((Rectangle2D) bounds.clone());
            graph.scrollRectToVisible(new Rectangle((int) b2.getX(), (int) b2.getY(), (int) b2.getWidth(), (int) b2.getHeight()));
        }
        }
        */

        /**
         * Invoked when the mouse pointer has been moved on a component (with no
         * buttons down).
         */
        @Override
        public void mouseMoved(MouseEvent e) {

            if (graph.isMoveable()) {
                super.mouseMoved(e);
            }

            Object o = graph.getFirstCellForLocation(e.getX(), e.getY());

            if (o != null && o instanceof VGraphCell) {

                selectedCell = (VGraphCell) o;

                Rectangle2D bounds = graph.getCellBounds(selectedCell);

                menu.show(graph, (int) (bounds.getX() + bounds.getWidth()),
                        (int) bounds.getY() + (int) (bounds.getHeight() - menu.getHeight()));
            }
        }
    };
}

From source file:CutAndPasteDemo.java

public CutAndPasteDemo() {
    super("Cut And Paste Demonstration");

    clipboard = getToolkit().getSystemClipboard();

    GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font font = new Font("LucidaSans", Font.PLAIN, 15);
    textArea1 = new JTextArea(davidMessage + andyMessage, 5, 25);
    textArea2 = new JTextArea("<Paste text here>", 5, 25);
    textArea1.setFont(font);// w w  w. ja v a2s .c  om
    textArea2.setFont(font);

    JPanel jPanel = new JPanel();
    JMenuBar jMenuBar = new JMenuBar();
    JMenuItem cutItem = new JMenuItem("Cut");
    JMenuItem pasteItem = new JMenuItem("Paste");
    JMenu jMenu = new JMenu("Edit");
    jMenu.add(cutItem);
    jMenu.add(pasteItem);

    cutItem.addActionListener(new CutActionListener());
    pasteItem.addActionListener(new PasteActionListener());

    jMenuBar.add(jMenu);
    jPanel.add(jMenuBar);

    jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS));
    jPanel.add(textArea1);
    jPanel.add(Box.createRigidArea(new Dimension(0, 10)));
    jPanel.add(textArea2);

    getContentPane().add(jPanel, BorderLayout.CENTER);
}

From source file:ec.nbdemetra.chainlinking.outlineview.ChainLinkingChart.java

private JMenu newExportMenu() {
    DemetraUI demetraUI = DemetraUI.getDefault();

    JMenu rslt = new JMenu("Export image to");
    rslt.setIcon(demetraUI.getPopupMenuIcon(FontAwesome.FA_FLOPPY_O));

    JMenuItem copy = new ActionMenuItem(ChartCommand.copyImage().toAction(chartPanel));
    copy.setText("Clipboard...");
    copy.setIcon(demetraUI.getPopupMenuIcon(FontAwesome.FA_CLIPBOARD));

    JMenuItem file = new ActionMenuItem(ChartCommand.saveImage().toAction(chartPanel));
    file.setText("File...");
    file.setIcon(demetraUI.getPopupMenuIcon(FontAwesome.FA_PICTURE_O));

    rslt.add(copy);/*from   w  ww .  jav a 2  s  .  co  m*/
    rslt.add(file);

    return rslt;
}

From source file:dmh.kuebiko.view.NoteStackFrame.java

/**
 * Create the frame.//from   www .j  a  va 2 s.com
 */
public NoteStackFrame(NoteManager noteMngr) {
    this.noteMngr = noteMngr;

    // Setup the various actions for the frame.
    noteMngr.addObserver(new Observer() {
        @Override
        public void update(Observable o, Object arg) {
            boolean stackChanged = (Boolean) arg;
            toggleUnsavedChangeIndicator(stackChanged);
            if (!stackChanged) {
                notePanel.getHuxleyUiManager().resetTextChanged();
            }
        }
    });

    ActionObserverUtil.registerEnMass(actionMngr, observable, new NewNoteAction(this), new OpenNoteAction(this),
            new DeleteNoteAction(this), new RenameNoteAction(this), new SaveStackAction(this));

    // Build the menus.
    menuBar = new JMenuBar();
    setJMenuBar(menuBar);

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

    newNoteMenuItem = new JMenuItem(actionMngr.getAction(NewNoteAction.class));
    fileMenu.add(newNoteMenuItem);

    JMenuItem openNoteMenuItem = new JMenuItem(actionMngr.getAction(OpenNoteAction.class));
    fileMenu.add(openNoteMenuItem);

    deleteNoteMenuItem = new JMenuItem(actionMngr.getAction(DeleteNoteAction.class));
    fileMenu.add(deleteNoteMenuItem);

    renameNoteMenuItem = new JMenuItem(actionMngr.getAction(RenameNoteAction.class));
    fileMenu.add(renameNoteMenuItem);

    fileMenu.addSeparator();

    newStackMenuItem = new JMenuItem(actionMngr.getAction(NewStackAction.class));
    fileMenu.add(newStackMenuItem);

    openStackMenuItem = new JMenuItem(actionMngr.getAction(OpenStackAction.class));
    fileMenu.add(openStackMenuItem);

    fileMenu.addSeparator();

    closeMenuItem = new JMenuItem("Close");
    closeMenuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_W, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    closeMenuItem.setEnabled(false);
    fileMenu.add(closeMenuItem);

    closeAllMenuItem = new JMenuItem("Close All");
    closeAllMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W,
            InputEvent.SHIFT_MASK | Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    closeAllMenuItem.setEnabled(false);
    fileMenu.add(closeAllMenuItem);

    fileMenu.addSeparator();

    saveMenuItem = new JMenuItem(actionMngr.getAction(SaveStackAction.class));
    fileMenu.add(saveMenuItem);

    saveAllMenuItem = new JMenuItem("Save All");
    saveAllMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
            InputEvent.SHIFT_MASK | Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    saveAllMenuItem.setEnabled(false);
    fileMenu.add(saveAllMenuItem);

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

    undoMenuItem = new JMenuItem("Undo");
    undoMenuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    editMenu.add(undoMenuItem);

    redoMenuItem = new JMenuItem("Redo"); // FIXME mac-specific keyboard shortcut
    redoMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z,
            InputEvent.SHIFT_MASK | Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    editMenu.add(redoMenuItem);

    editMenu.addSeparator();

    cutMenuItem = new JMenuItem(actionMngr.getAction(DefaultEditorKit.CutAction.class));
    cutMenuItem.setText("Cut");
    cutMenuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    editMenu.add(cutMenuItem);

    copyMenuItem = new JMenuItem(actionMngr.getAction(DefaultEditorKit.CopyAction.class));
    copyMenuItem.setText("Copy");
    copyMenuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    editMenu.add(copyMenuItem);

    pasteMenuItem = new JMenuItem(actionMngr.getAction(DefaultEditorKit.PasteAction.class));
    pasteMenuItem.setText("Paste");
    pasteMenuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    editMenu.add(pasteMenuItem);

    textMenu = new JMenu("Text");
    menuBar.add(textMenu);

    JMenu windowMenu = new JMenu("Window");
    menuBar.add(windowMenu);

    initialize();
    additionalSetup();
}

From source file:misc.ActionDemo.java

public JMenuBar createMenuBar() {
    JMenuItem menuItem = null;//ww w  .j  a  v a 2 s .  c o m
    JMenuBar menuBar;

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

    //Create the first menu.
    JMenu mainMenu = new JMenu("Menu");

    Action[] actions = { leftAction, middleAction, rightAction };
    for (int i = 0; i < actions.length; i++) {
        menuItem = new JMenuItem(actions[i]);
        menuItem.setIcon(null); //arbitrarily chose not to use icon
        mainMenu.add(menuItem);
    }

    //Set up the menu bar.
    menuBar.add(mainMenu);
    menuBar.add(createAbleMenu());
    return menuBar;
}