Example usage for javax.swing JMenuBar removeAll

List of usage examples for javax.swing JMenuBar removeAll

Introduction

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

Prototype

public void removeAll() 

Source Link

Document

Removes all the components from this container.

Usage

From source file:ActionsMenuBar.java

public static void main(String args[]) {
    final JFrame frame = new JFrame("TextAction Usage");
    Container contentPane = frame.getContentPane();
    final JScrollPane scrollPane = new JScrollPane();
    contentPane.add(scrollPane, BorderLayout.CENTER);

    final JMenuBar menuBar = new JMenuBar();
    frame.setJMenuBar(menuBar);//w  ww .j a va2s.  co m

    ActionListener actionListener = new ActionListener() {
        JTextComponent component;

        public void actionPerformed(ActionEvent actionEvent) {
            // Determine which component selected
            String command = actionEvent.getActionCommand();
            if (command.equals("JTextField")) {
                component = new JTextField();
            } else if (command.equals("JPasswordField")) {
                component = new JPasswordField();
            } else if (command.equals("JTextArea")) {
                component = new JTextArea();
            } else if (command.equals("JTextPane")) {
                component = new JTextPane();
            } else {
                component = new JEditorPane();
            }
            scrollPane.setViewportView(component);
            // Process action list
            Action actions[] = component.getActions();
            menuBar.removeAll();
            menuBar.revalidate();
            JMenu menu = null;
            for (int i = 0, n = actions.length; i < n; i++) {
                if ((i % 10) == 0) {
                    menu = new JMenu("From " + i);
                    menuBar.add(menu);
                }
                menu.add(actions[i]);
            }
            menuBar.revalidate();
        }
    };

    String components[] = { "JTextField", "JPasswordField", "JTextArea", "JTextPane", "JEditorPane" };
    final Container componentsContainer = RadioButtonUtils.createRadioButtonGrouping(components,
            "Pick to List Actions", actionListener);
    contentPane.add(componentsContainer, BorderLayout.WEST);

    frame.setSize(400, 300);
    frame.setVisible(true);
}

From source file:Main.java

/**
 * @param newMenu//from  w  w w .j a v a2s . c o m
 * @param menuBar
 * @param index
 * @return The same JMenuBar, for cascading.
 *         TODO See if the same thing can be done with Container.add( component, index )
 */
public static JMenuBar addMenuAt(JMenu newMenu, JMenuBar menuBar, int index) {

    ArrayList menuList = new ArrayList();
    for (int i = 0; i < menuBar.getMenuCount(); i++) {
        if (i == index) {
            menuList.add(newMenu);
        }
        menuList.add(menuBar.getMenu(i));
    }
    menuBar.removeAll();
    //        menuBar = new JMenuBar();
    for (int i = 0; i < menuList.size(); i++) {
        JMenu menu = (JMenu) menuList.get(i);
        menuBar.add(menu);
    }
    return menuBar;
}

From source file:org.openmicroscopy.shoola.agents.fsimporter.view.ImporterUI.java

/**
  * Creates the menu bar./*from  w  w  w .  j a v  a2 s . c o m*/
  * 
  * @return The menu bar.
  */
private JMenuBar createMenuBar() {
    TaskBar tb = ImporterAgent.getRegistry().getTaskBar();
    JMenuBar bar = tb.getTaskBarMenuBar();
    if (!model.isMaster())
        return bar;
    JMenu[] existingMenus = new JMenu[bar.getMenuCount()];
    for (int i = 0; i < existingMenus.length; i++) {
        existingMenus[i] = bar.getMenu(i);
    }

    bar.removeAll();
    bar.add(createFileMenu());
    for (int i = 0; i < existingMenus.length; i++) {
        if (i != TaskBar.FILE_MENU)
            bar.add(existingMenus[i]);
    }
    return bar;
}

From source file:pl.otros.logview.gui.LogViewMainFrame.java

private void initMenu() {
    JMenuBar menuBar = getJMenuBar();
    if (menuBar == null) {
        menuBar = new JMenuBar();
        setJMenuBar(menuBar);/* w w  w  . j  a v a2  s  . c  om*/
    }
    menuBar.removeAll();
    JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic(KeyEvent.VK_F);
    JLabel labelOpenLog = new JLabel("Open log", Icons.FOLDER_OPEN, SwingConstants.LEFT);
    Font menuGroupFont = labelOpenLog.getFont().deriveFont(13f).deriveFont(Font.BOLD);
    labelOpenLog.setFont(menuGroupFont);
    fileMenu.add(labelOpenLog);
    JMenuItem openAutoDetectLog = new JMenuItem("Open log with autodetect type");
    openAutoDetectLog.addActionListener(new ImportLogWithAutoDetectedImporterActionListener(otrosApplication));
    openAutoDetectLog.setMnemonic(KeyEvent.VK_O);
    openAutoDetectLog.setIcon(Icons.WIZARD);
    fileMenu.add(openAutoDetectLog);
    JMenuItem tailAutoDetectLog = new JMenuItem("Tail log with autodetect type");
    tailAutoDetectLog.addActionListener(new TailLogWithAutoDetectActionListener(otrosApplication));
    tailAutoDetectLog.setMnemonic(KeyEvent.VK_T);
    tailAutoDetectLog.setIcon(Icons.ARROW_REPEAT);
    fileMenu.add(tailAutoDetectLog);
    fileMenu.add(new TailMultipleFilesIntoOneView(otrosApplication));
    fileMenu.add(new ConnectToSocketHubAppenderAction(otrosApplication));
    fileMenu.add(new JSeparator());
    JLabel labelLogInvestigation = new JLabel("Log investigation", SwingConstants.LEFT);
    labelLogInvestigation.setFont(menuGroupFont);
    fileMenu.add(labelLogInvestigation);
    fileMenu.add(new OpenLogInvestigationAction(otrosApplication));
    JMenuItem saveLogsInvest = new JMenuItem(new SaveLogInvestigationAction(otrosApplication));
    enableDisableComponetsForTabs.addComponet(saveLogsInvest);
    fileMenu.add(saveLogsInvest);
    fileMenu.add(new JSeparator());
    LogImporter[] importers = new LogImporter[0];
    importers = logImportersContainer.getElements().toArray(importers);
    for (LogImporter logImporter : importers) {
        JMenuItem openLog = new JMenuItem("Open " + logImporter.getName() + " log");
        openLog.addActionListener(new ImportLogWithGivenImporterActionListener(otrosApplication, logImporter));
        if (logImporter.getKeyStrokeAccelelator() != null) {
            openLog.setAccelerator(KeyStroke.getKeyStroke(logImporter.getKeyStrokeAccelelator()));
        }
        if (logImporter.getMnemonic() > 0) {
            openLog.setMnemonic(logImporter.getMnemonic());
        }
        Icon icon = logImporter.getIcon();
        if (icon != null) {
            openLog.setIcon(icon);
        }
        fileMenu.add(openLog);
    }
    fileMenu.add(new JSeparator());
    JLabel labelTailLog = new JLabel("Tail log [from begging of file]", Icons.ARROW_REPEAT,
            SwingConstants.LEFT);
    labelTailLog.setFont(menuGroupFont);
    fileMenu.add(labelTailLog);
    for (LogImporter logImporter : importers) {
        JMenuItem openLog = new JMenuItem("Tail " + logImporter.getName() + " log");
        openLog.addActionListener(new TailLogActionListener(otrosApplication, logImporter));
        if (logImporter.getKeyStrokeAccelelator() != null) {
            openLog.setAccelerator(KeyStroke.getKeyStroke(logImporter.getKeyStrokeAccelelator()));
        }
        if (logImporter.getMnemonic() > 0) {
            openLog.setMnemonic(logImporter.getMnemonic());
        }
        Icon icon = logImporter.getIcon();
        if (icon != null) {
            openLog.setIcon(icon);
        }
        fileMenu.add(openLog);
    }
    JMenuItem exitMenuItem = new JMenuItem("Exit", 'e');
    exitMenuItem.setIcon(Icons.TURN_OFF);
    exitMenuItem.setAccelerator(KeyStroke.getKeyStroke("control F4"));
    exitAction = new ExitAction(this);
    exitMenuItem.addActionListener(exitAction);
    fileMenu.add(new JSeparator());
    fileMenu.add(exitMenuItem);
    JMenu toolsMenu = new JMenu("Tools");
    toolsMenu.setMnemonic(KeyEvent.VK_T);
    JMenuItem closeAll = new JMenuItem(new CloseAllTabsAction(otrosApplication));
    enableDisableComponetsForTabs.addComponet(closeAll);
    ArrayList<SocketLogReader> logReaders = new ArrayList<SocketLogReader>();
    toolsMenu.add(new JMenuItem(new StartSocketListener(otrosApplication, logReaders)));
    toolsMenu.add(new JMenuItem(new StopAllSocketListeners(otrosApplication, logReaders)));
    toolsMenu.add(new ShowMarkersEditor(otrosApplication));
    toolsMenu.add(new ShowLog4jPatternParserEditor(otrosApplication));
    toolsMenu.add(new ShowMessageColorizerEditor(otrosApplication));
    toolsMenu.add(new ShowLoadedPlugins(otrosApplication));
    toolsMenu.add(new ShowOlvLogs(otrosApplication));
    toolsMenu.add(new OpenPreferencesAction(otrosApplication));
    toolsMenu.add(closeAll);
    JMenu pluginsMenu = new JMenu("Plugins");
    otrosApplication.setPluginsMenu(pluginsMenu);
    JMenu helpMenu = new JMenu("Help");
    JMenuItem about = new JMenuItem("About");
    AboutAction action = new AboutAction(otrosApplication);
    action.putValue(Action.NAME, "About");
    about.setAction(action);
    helpMenu.add(about);
    helpMenu.add(new GoToDonatePageAction(otrosApplication));
    JMenuItem checkForNewVersion = new JMenuItem(new CheckForNewVersionAction(otrosApplication));
    helpMenu.add(checkForNewVersion);
    helpMenu.add(new GettingStartedAction(otrosApplication));
    menuBar.add(fileMenu);
    menuBar.add(toolsMenu);
    menuBar.add(pluginsMenu);
    menuBar.add(helpMenu);
}