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:br.org.acessobrasil.ases.ferramentas_de_reparo.vista.corretor_eventos.PanelCorretorEventos.java

/**
 * Cria o menu/*from   ww  w  .  ja  va2  s.  com*/
 * 
 * @return o menu
 */
private JMenuBar criaMenuBar() {
    menuBar = new JMenuBar();
    menuBar.setBackground(frameSilvinha.corDefault);

    JMenu menuArquivo = new JMenu(XHTML_Panel.ARQUIVO);
    menuArquivo.setMnemonic('A');
    menuArquivo.setMnemonic(KeyEvent.VK_A);

    JMenu avaliadores = new JMenu();
    MenuSilvinha menuSilvinha = new MenuSilvinha(frameSilvinha, null);
    menuSilvinha.criaMenuAvaliadores(avaliadores);
    // menuArquivo.add(avaliadores);
    // menuArquivo.add(new JSeparator());

    JMenuItem btnAbrir = new JMenuItem(XHTML_Panel.BTN_ABRIR);
    btnAbrir.addActionListener(this);
    btnAbrir.setActionCommand("Abrir");
    btnAbrir.setMnemonic('A');
    btnAbrir.setAccelerator(
            javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, ActionEvent.CTRL_MASK));
    btnAbrir.setMnemonic(KeyEvent.VK_A);
    btnAbrir.setToolTipText(XHTML_Panel.DICA_ABRIR);
    btnAbrir.getAccessibleContext().setAccessibleDescription(XHTML_Panel.DICA_ABRIR);
    menuArquivo.add(btnAbrir);

    JMenuItem btnAbrirUrl = new JMenuItem(XHTML_Panel.BTN_ABRIR_URL);
    btnAbrirUrl.addActionListener(this);
    btnAbrirUrl.setActionCommand("AbrirURL");
    btnAbrirUrl.setMnemonic('U');
    btnAbrirUrl.setAccelerator(
            javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_U, ActionEvent.CTRL_MASK));
    btnAbrirUrl.setMnemonic(KeyEvent.VK_U);
    btnAbrirUrl.setToolTipText(XHTML_Panel.DICA_ABRIR);
    btnAbrirUrl.getAccessibleContext().setAccessibleDescription(XHTML_Panel.DICA_ABRIR);
    menuArquivo.add(btnAbrirUrl);

    miBtnSalvar.addActionListener(this);
    miBtnSalvar.setActionCommand("Salvar");
    miBtnSalvar.setMnemonic('S');
    miBtnSalvar.setAccelerator(
            javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, ActionEvent.CTRL_MASK));
    miBtnSalvar.setMnemonic(KeyEvent.VK_S);
    miBtnSalvar.getAccessibleContext().setAccessibleDescription(XHTML_Panel.BTN_SALVAR);
    miBtnSalvar.getAccessibleContext().setAccessibleDescription(XHTML_Panel.DICA_SALVAR);
    menuArquivo.add(miBtnSalvar);

    JMenuItem btnSalvarAs = new JMenuItem(XHTML_Panel.BTN_SALVAR_COMO);
    btnSalvarAs.addActionListener(this);
    btnSalvarAs.setActionCommand("SaveAs");
    btnSalvarAs.setMnemonic('c');
    btnSalvarAs.setMnemonic(KeyEvent.VK_C);
    // btnSalvarAs.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N,
    // ActionEvent.CTRL_MASK));
    btnSalvarAs.setToolTipText(XHTML_Panel.DICA_SALVAR_COMO);
    btnSalvarAs.getAccessibleContext().setAccessibleDescription(XHTML_Panel.DICA_SALVAR_COMO);
    menuArquivo.add(btnSalvarAs);

    JMenuItem btnFechar = new JMenuItem(XHTML_Panel.SAIR);
    btnFechar.addActionListener(this);
    btnFechar.setActionCommand("Sair");
    btnFechar.setMnemonic('a');
    btnFechar.setMnemonic(KeyEvent.VK_A);
    btnFechar.setToolTipText(XHTML_Panel.DICA_SAIR);
    btnFechar.getAccessibleContext().setAccessibleDescription(XHTML_Panel.DICA_SAIR);
    menuArquivo.add(btnFechar);

    menuBar.add(menuArquivo);

    JMenu menuEditar = new JMenu(XHTML_Panel.EDITAR);
    menuBar.add(criaMenuEditar(menuEditar));

    menuBar.add(avaliadores);
    JMenu menuSimuladores = new JMenu();
    menuSilvinha.criaMenuSimuladores(menuSimuladores);
    menuBar.add(menuSimuladores);

    JMenu mnFerramenta = new JMenu();
    menuSilvinha.criaMenuFerramentas(mnFerramenta);
    menuBar.add(mnFerramenta);

    JMenu menuAjuda = new JMenu(XHTML_Panel.AJUDA);
    menuSilvinha.criaMenuAjuda(menuAjuda);
    menuBar.add(menuAjuda);

    return menuBar;
}

From source file:gdt.jgui.entity.JEntityDigestDisplay.java

/**
 * Get the context menu.//w  ww  . ja  v  a2s  . co  m
 * @return the context menu.
 */
@Override
public JMenu getContextMenu() {
    JMenu menu = new JMenu("Context");
    menu.setName("Context");
    JMenuItem facetItem = new JMenuItem("Facets");
    facetItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Properties locator = Locator.toProperties(locator$);
            String entihome$ = locator.getProperty(Entigrator.ENTIHOME);
            String entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY);
            JEntityFacetPanel efp = new JEntityFacetPanel();
            String efpLocator$ = efp.getLocator();
            efpLocator$ = Locator.append(efpLocator$, Entigrator.ENTIHOME, entihome$);
            efpLocator$ = Locator.append(efpLocator$, EntityHandler.ENTITY_KEY, entityKey$);
            JConsoleHandler.execute(console, efpLocator$);
        }
    });
    menu.add(facetItem);

    JMenuItem structureItem = new JMenuItem("Structure");
    structureItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Properties locator = Locator.toProperties(locator$);
            String entihome$ = locator.getProperty(Entigrator.ENTIHOME);
            String entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY);
            JEntityStructurePanel esp = new JEntityStructurePanel();
            String espLocator$ = esp.getLocator();
            espLocator$ = Locator.append(espLocator$, Entigrator.ENTIHOME, entihome$);
            espLocator$ = Locator.append(espLocator$, EntityHandler.ENTITY_KEY, entityKey$);
            JConsoleHandler.execute(console, espLocator$);

        }
    });
    menu.add(structureItem);

    JMenuItem refreshItem = new JMenuItem("Refresh");
    refreshItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Properties locator = Locator.toProperties(locator$);
            String entihome$ = locator.getProperty(Entigrator.ENTIHOME);
            String entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY);
            JEntityDigestDisplay edp = new JEntityDigestDisplay();
            String edpLocator$ = edp.getLocator();
            edpLocator$ = Locator.append(edpLocator$, Entigrator.ENTIHOME, entihome$);
            if (selection$ != null)
                edpLocator$ = Locator.append(edpLocator$, SELECTION, Locator.compressText(selection$));
            edpLocator$ = Locator.append(edpLocator$, EntityHandler.ENTITY_KEY, entityKey$);
            JConsoleHandler.execute(console, edpLocator$);
        }
    });
    menu.add(refreshItem);
    return menu;
}

From source file:org.nebulaframework.ui.swing.cluster.ClusterMainUI.java

/**
 * Setups the Menu Bar//  w  ww  . j av  a  2 s. co  m
 * @return
 */
private JMenuBar setupMenu() {
    JMenuBar menuBar = new JMenuBar();

    /* -- Cluster Menu -- */
    JMenu clusterMenu = new JMenu("Cluster");
    clusterMenu.setMnemonic(KeyEvent.VK_C);
    menuBar.add(clusterMenu);

    // Discover Submenu
    JMenu clusterDiscoverMenu = new JMenu("Disover Peers");
    clusterDiscoverMenu.setMnemonic(KeyEvent.VK_D);
    clusterMenu.add(clusterDiscoverMenu);

    // Discover -> Multicast
    JMenuItem clusterDiscoverMulticast = new JMenuItem("Multicast");
    clusterDiscoverMulticast.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F9, 0));
    clusterDiscoverMulticast.setEnabled(false);
    clusterDiscoverMulticast.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            doDiscoverMulticast();
        }
    });
    clusterDiscoverMenu.add(clusterDiscoverMulticast);
    addUIElement("menu.cluster.discover.multicast", clusterDiscoverMulticast); // Add to components map

    // Discover -> WS
    JMenuItem clusterDiscoverWS = new JMenuItem("Colombus Web Service");
    clusterDiscoverWS.setEnabled(false);
    clusterDiscoverWS.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F10, 0));
    clusterDiscoverWS.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            doDiscoverWS();
        }
    });
    clusterDiscoverMenu.add(clusterDiscoverWS);
    addUIElement("menu.cluster.discover.ws", clusterDiscoverWS); // Add to components map

    clusterMenu.addSeparator();

    // Cluster-> Shutdown
    JMenuItem clusterShutdownItem = new JMenuItem("Shutdown", 'u');
    clusterShutdownItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0));
    clusterShutdownItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            doShutdownCluster();
        }
    });
    clusterMenu.add(clusterShutdownItem);
    addUIElement("menu.cluster.shutdown", clusterShutdownItem); // Add to components map

    /* -- Options Menu -- */
    JMenu optionsMenu = new JMenu("Options");
    optionsMenu.setMnemonic(KeyEvent.VK_O);
    menuBar.add(optionsMenu);

    // Configuration
    JMenuItem optionsConfigItem = new JMenuItem("Configuration...", 'C');
    optionsConfigItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            showConfiguration();
        }
    });
    optionsMenu.add(optionsConfigItem);
    optionsConfigItem.setEnabled(false); // TODO Create Configuration Options

    /* -- Help Menu -- */
    JMenu helpMenu = new JMenu("Help");
    helpMenu.setMnemonic(KeyEvent.VK_H);
    menuBar.add(helpMenu);

    // Help Contents
    JMenuItem helpContentsItem = new JMenuItem("Help Contents", 'H');
    helpContentsItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
    helpContentsItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            showHelp();
        }
    });
    helpMenu.add(helpContentsItem);

    helpMenu.addSeparator();

    JMenuItem helpAboutItem = new JMenuItem("About", 'A');
    helpAboutItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            showAbout();
        }
    });
    helpMenu.add(helpAboutItem);

    return menuBar;
}

From source file:gdt.jgui.entity.webset.JWeblinkEditor.java

/**
 * Get the context menu.//from   www.j av  a2s  .c  om
 * @return the 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) {
            save();
            if (requesterResponseLocator$ != null) {
                try {
                    byte[] ba = Base64.decodeBase64(requesterResponseLocator$);
                    String responseLocator$ = new String(ba, "UTF-8");
                    JConsoleHandler.execute(console, responseLocator$);
                } catch (Exception ee) {
                    Logger.getLogger(getClass().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) {
            try {
                browseUrl(console, locator$);
            } catch (Exception ee) {
                Logger.getLogger(getClass().getName()).info(ee.toString());
            }
        }
    });
    menu.add(cancelItem);
    menu.addSeparator();
    JMenuItem browseItem = new JMenuItem("Browse");
    browseItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                Desktop.getDesktop().browse(new URI(addressField.getText()));
            } catch (Exception ee) {
                Logger.getLogger(JWeblinkEditor.class.getName()).info(ee.toString());
            }
        }
    });
    menu.add(browseItem);
    return menu;
}

From source file:edu.clemson.cs.nestbed.client.gui.ConfigManagerFrame.java

private final JMenu buildProgramMenu() {
    final JMenu menu = new JMenu("Program");
    final JMenuItem uploadProgram = new JMenuItem("Upload Program");
    final JMenuItem deleteProgram = new JMenuItem("Delete Program");
    final JMenuItem configureAll = new JMenuItem("Configure All Motes");
    final JMenuItem unconfigureAll = new JMenuItem("Unconfigure All " + "Motes");

    uploadProgram.addActionListener(new UploadProgramActionListener());
    menu.add(uploadProgram);

    deleteProgram.addActionListener(new DeleteProgramActionListener());
    menu.add(deleteProgram);//from w  w w  .j a  v a  2s . c om

    menu.add(new JSeparator());

    configureAll.addActionListener(new ConfigureAllActionListener());
    menu.add(configureAll);

    unconfigureAll.addActionListener(new UnconfigureAllActionListener());
    menu.add(unconfigureAll);

    menu.addMenuListener(new ProgramMenuListener(deleteProgram));

    return menu;
}

From source file:Main.java

public Main() {
    menuBar = new JMenuBar();
    JMenu justifyMenu = new JMenu("Justify");
    ActionListener actionPrinter = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Action [" + e.getActionCommand() + "] performed!\n");
        }//from   w  w w  .  jav  a2s .  c o m
    };
    JCheckBoxMenuItem leftJustify = new JCheckBoxMenuItem("Left", new ImageIcon("1.gif"));
    leftJustify.setHorizontalTextPosition(JMenuItem.RIGHT);
    leftJustify
            .setAccelerator(KeyStroke.getKeyStroke('L', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    leftJustify.addActionListener(actionPrinter);
    JCheckBoxMenuItem rightJustify = new JCheckBoxMenuItem("Right", new ImageIcon("2.gif"));
    rightJustify.setHorizontalTextPosition(JMenuItem.RIGHT);
    rightJustify
            .setAccelerator(KeyStroke.getKeyStroke('R', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    rightJustify.addActionListener(actionPrinter);
    JCheckBoxMenuItem centerJustify = new JCheckBoxMenuItem("Center", new ImageIcon("3.gif"));
    centerJustify.setHorizontalTextPosition(JMenuItem.RIGHT);
    centerJustify
            .setAccelerator(KeyStroke.getKeyStroke('M', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    centerJustify.addActionListener(actionPrinter);
    JCheckBoxMenuItem fullJustify = new JCheckBoxMenuItem("Full", new ImageIcon("4.gif"));
    fullJustify.setHorizontalTextPosition(JMenuItem.RIGHT);
    fullJustify
            .setAccelerator(KeyStroke.getKeyStroke('F', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    fullJustify.addActionListener(actionPrinter);

    justifyMenu.add(leftJustify);
    justifyMenu.add(rightJustify);
    justifyMenu.add(centerJustify);
    justifyMenu.add(fullJustify);

    menuBar.add(justifyMenu);
    menuBar.setBorder(new BevelBorder(BevelBorder.RAISED));

}

From source file:com.eviware.soapui.SoapUI.java

private JMenuItem buildRecentMenu() {
    JMenu recentMenu = new JMenu("Recent");

    JMenu recentProjectsMenu = new JMenu("Projects");
    JMenu recentWorkspacesMenu = new JMenu("Workspaces");
    JMenu recentEditorsMenu = new JMenu("Editors");

    recentMenu.add(recentEditorsMenu);/*w  w  w.j a  v  a  2 s  .  c o  m*/
    recentMenu.add(recentProjectsMenu);
    recentMenu.add(recentWorkspacesMenu);

    MenuScroller.setScrollerFor(recentEditorsMenu, 24, 125, 0, 1);
    MenuScroller.setScrollerFor(recentProjectsMenu, 24, 125, 0, 1);
    MenuScroller.setScrollerFor(recentWorkspacesMenu, 24, 125, 0, 1);

    RecentItemsListener recentItemsListener = new RecentItemsListener(recentWorkspacesMenu, recentProjectsMenu,
            recentEditorsMenu);
    workspace.addWorkspaceListener(recentItemsListener);
    desktop.addDesktopListener(recentItemsListener);

    return recentMenu;
}

From source file:net.panthema.BispanningGame.GamePanel.java

public void addPopupActions(JPopupMenu popup) {

    popup.add(new AbstractAction("Center Graph") {
        private static final long serialVersionUID = 571719411574657791L;

        public void actionPerformed(ActionEvent e) {
            centerAndScaleGraph();// www  .j  a va  2 s  .c om
        }
    });

    popup.add(new AbstractAction("Relayout Graph") {
        private static final long serialVersionUID = 571719411573657791L;

        public void actionPerformed(ActionEvent e) {
            relayoutGraph();
        }
    });

    popup.add(new AbstractAction("Reset Board Colors") {
        private static final long serialVersionUID = 571719411573657796L;

        public void actionPerformed(ActionEvent e) {
            mGraph.updateOriginalColor();
            mTurnNum = 0;
            putLog("Resetting game graph's colors.");
            updateGraphMessage();
            mVV.repaint();
        }
    });

    popup.add(new AbstractAction(
            allowFreeExchange ? "Restrict to Unique Exchanges" : "Allow Free Edge Exchanges") {
        private static final long serialVersionUID = 571719411573657798L;

        public void actionPerformed(ActionEvent e) {
            allowFreeExchange = !allowFreeExchange;
            mVV.repaint();
        }
    });

    popup.add(new AbstractAction((mAutoPlayBob ? "Disable" : "Enable") + " Autoplay of Bob's Moves") {
        private static final long serialVersionUID = 571719413573657798L;

        public void actionPerformed(ActionEvent e) {
            mAutoPlayBob = !mAutoPlayBob;
        }
    });

    popup.addSeparator();

    JMenu newGraph = new JMenu("New Random Graph");
    for (int i = 0; i < actionRandomGraph.length; ++i) {
        if (actionRandomGraph[i] != null)
            newGraph.add(actionRandomGraph[i]);
    }
    newGraph.addSeparator();
    newGraph.add(getActionNewGraphType());
    popup.add(newGraph);

    JMenu newNamedGraph = new JMenu("New Named Graph");
    for (int i = 0; i < actionNamedGraph.size(); ++i) {
        if (actionNamedGraph.get(i) != null)
            newNamedGraph.add(actionNamedGraph.get(i));
    }
    popup.add(newNamedGraph);

    popup.add(new AbstractAction("Show GraphString") {
        private static final long serialVersionUID = 545719411573657792L;

        public void actionPerformed(ActionEvent e) {
            JEditorPane text = new JEditorPane("text/plain",
                    GraphString.write_graph(mGraph, mVV.getModel().getGraphLayout()));
            text.setEditable(false);
            text.setPreferredSize(new Dimension(300, 125));
            JOptionPane.showMessageDialog(null, text, "GraphString Serialization",
                    JOptionPane.INFORMATION_MESSAGE);
        }
    });

    popup.add(new AbstractAction("Load GraphString") {
        private static final long serialVersionUID = 8636579131902717983L;

        public void actionPerformed(ActionEvent e) {
            String input = JOptionPane.showInputDialog(null, "Enter GraphString:", "");
            if (input == null)
                return;
            loadGraphString(input);
        }
    });

    popup.add(new AbstractAction("Show graph6") {
        private static final long serialVersionUID = 571719411573657792L;

        public void actionPerformed(ActionEvent e) {
            JTextArea text = new JTextArea(Graph6.write_graph6(mGraph));
            JOptionPane.showMessageDialog(null, text, "graph6 Serialization", JOptionPane.INFORMATION_MESSAGE);
        }
    });

    popup.add(new AbstractAction("Load graph6/sparse6") {
        private static final long serialVersionUID = 571719411573657792L;

        public void actionPerformed(ActionEvent e) {
            String input = JOptionPane.showInputDialog(null, "Enter graph6/sparse6 string:", "");
            if (input == null)
                return;
            MyGraph g = Graph6.read_graph6(input);
            setNewGraph(g);
        }
    });

    popup.add(new AbstractAction("Read GraphML") {
        private static final long serialVersionUID = 571719411573657794L;

        public void actionPerformed(ActionEvent e) {
            try {
                readGraphML();
            } catch (IOException e1) {
                showStackTrace(e1);
            } catch (GraphIOException e1) {
                showStackTrace(e1);
            }
        }
    });

    popup.add(new AbstractAction("Write GraphML") {
        private static final long serialVersionUID = 571719411573657795L;

        public void actionPerformed(ActionEvent e) {
            try {
                writeGraphML();
            } catch (IOException e1) {
                showStackTrace(e1);
            }
        }
    });

    popup.add(new AbstractAction("Write PDF") {
        private static final long serialVersionUID = 571719411573657793L;

        public void actionPerformed(ActionEvent e) {
            try {
                writePdf();
            } catch (FileNotFoundException e1) {
                showStackTrace(e1);
            } catch (DocumentException de) {
                System.err.println(de.getMessage());
            }
        }
    });
}

From source file:ca.phon.app.project.ProjectWindow.java

@Override
public void setJMenuBar(JMenuBar menu) {
    super.setJMenuBar(menu);

    JMenu projectMenu = new JMenu("Project");

    int projectMenuIndex = -1;
    // get the edit menu and add view commands
    for (int i = 0; i < menu.getMenuCount(); i++) {
        JMenu currentBar = menu.getMenu(i);

        if (currentBar != null && currentBar.getText() != null && currentBar.getText().equals("Workspace")) {
            projectMenuIndex = i + 1;/*  ww  w  .ja  v  a  2s.  co m*/
        }
    }

    if (projectMenuIndex > 0) {
        menu.add(projectMenu, projectMenuIndex);
    }

    // refresh lists 
    final RefreshAction refreshItem = new RefreshAction(this);
    projectMenu.add(refreshItem);
    projectMenu.addSeparator();

    // create corpus item
    final NewCorpusAction newCorpusItem = new NewCorpusAction(this);
    projectMenu.add(newCorpusItem);

    //       create corpus item
    final NewSessionAction newSessionItem = new NewSessionAction(this);
    projectMenu.add(newSessionItem);

    projectMenu.addSeparator();

    final AnonymizeAction anonymizeParticipantInfoItem = new AnonymizeAction(this);
    projectMenu.add(anonymizeParticipantInfoItem);

    final CheckTranscriptionsAction repairItem = new CheckTranscriptionsAction(this);
    projectMenu.add(repairItem);

    // merge/split sessions
    final DeriveSessionAction deriveItem = new DeriveSessionAction(this);
    projectMenu.add(deriveItem);

    final JMenu teamMenu = new JMenu("Team");
    teamMenu.addMenuListener(new MenuListener() {

        @Override
        public void menuSelected(MenuEvent e) {
            teamMenu.removeAll();
            if (getProject() != null) {
                final ProjectGitController gitController = new ProjectGitController(getProject());
                if (gitController.hasGitFolder()) {
                    teamMenu.add(new CommitAction(ProjectWindow.this));

                    teamMenu.addSeparator();

                    teamMenu.add(new PullAction(ProjectWindow.this));
                    teamMenu.add(new PushAction(ProjectWindow.this));

                } else {
                    final InitAction initRepoAct = new InitAction(ProjectWindow.this);
                    teamMenu.add(initRepoAct);
                }
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {

        }

        @Override
        public void menuCanceled(MenuEvent e) {

        }
    });
    projectMenu.addSeparator();
    projectMenu.add(teamMenu);
}

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));
            }/*  ww w  . ja va 2 s. 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;
                }
            }
        }
    }
}