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:net.brtly.monkeyboard.gui.MasterControlPanel.java

public MasterControlPanel(JFrame frame) {
    _frame = frame;/*from ww  w .j a v  a 2  s .  c om*/
    initWindowListener(frame);

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

    JMenu mnActions = new JMenu("Actions");
    menuBar.add(mnActions);

    JMenu mnDebug = new JMenu("Debug");
    mnActions.add(mnDebug);

    JMenuItem mntmAddPluginpanel = new JMenuItem("Request null PluginPanel");
    mntmAddPluginpanel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            System.out.println("Requesting null PluginPanel");
            // TODO
        }
    });
    mnDebug.add(mntmAddPluginpanel);

    JMenu mnOptions = new JMenu("Options");
    menuBar.add(mnOptions);

    _viewMenu = new JMenu("Views");

    _viewMenu.addMenuListener(new MenuListener() {

        @Override
        public void menuCanceled(MenuEvent arg0) {
        }

        @Override
        public void menuDeselected(MenuEvent arg0) {
        }

        @Override
        public void menuSelected(MenuEvent arg0) {
            updateViewMenu();
        }

    });
    menuBar.add(_viewMenu);

    // INITIALIZE MANAGERS
    // TODO: maybe call this in the Runnable and fire an event when finished
    _eventBus = new SwingEventBus();
    _eventBus.register(this);
    DeviceManager.init(_eventBus);

    _pluginManager = new PluginManager(_eventBus);
    _pluginManager.loadPlugins();

    // create the status bar panel and shove it down the bottom of the frame
    statusPanel = new StatusBar(frame);
    _frame.getContentPane().add(statusPanel, BorderLayout.SOUTH);

    _dockController = new CControl(frame);
    _frame.getContentPane().add(_dockController.getContentArea(), BorderLayout.CENTER);
    _panelFactory = new PluginPanelDockableFactory(_pluginManager);
    _dockController.addMultipleDockableFactory(PluginPanelDockableFactory.ID, _panelFactory);
    _dockController.createWorkingArea("root");

    updateViewMenu();

    EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
            DeviceManager.start(null);
        }
    });

    _runOnClose.add(new Runnable() {
        public void run() {
            _dockController.destroy();
            DeviceManager.stop();
            DeviceManager.shutdown();
            System.exit(0);
        }
    });
}

From source file:com.quattroresearch.antibody.plugin.PluginLoader.java

/**
 * Loads the menu plugins and inserts them into the menu.
 *//*ww  w.  j a  v a2  s .  c  om*/
public void loadMenuPlugins() {
    String menuPluginConfig = PreferencesService.getInstance().getApplicationPrefs().getString("plugins.menu");
    if (menuPluginConfig == null) {
        return;
    }
    String[] menuPlugins = menuPluginConfig.split(";");
    for (String singleConfig : menuPlugins) {
        try {

            Class<?> clazz = classLoader.findClass(singleConfig);

            if (clazz != null) {
                Constructor<?> constructor;

                constructor = clazz.getDeclaredConstructor(JFrame.class);

                AbstractEditorAction action = (AbstractEditorAction) constructor
                        .newInstance(UIService.getInstance().getMainFrame());

                boolean isAdded = false;
                JMenuBar menubar = UIService.getInstance().getMainFrame().getJMenuBar();
                for (int i = 0; i < menubar.getMenuCount(); i++) {
                    JMenu menu = menubar.getMenu(i);
                    if (menu.getText().equals(action.getMenuName())) {
                        menu.add(action);
                        isAdded = true;
                        break;
                    }
                }
                if (!isAdded) {
                    JMenu newMenu = new JMenu(action.getMenuName());
                    newMenu.add(action);
                    menubar.add(newMenu, menubar.getMenuCount() - 1);
                }
            }
        } catch (ClassNotFoundException exc) {
            System.err.println("Menu Plugin class was not found: " + exc.toString());
        } catch (Exception exc) {
            System.err.println(exc.toString());
        }
    }
}

From source file:ucar.unidata.idv.flythrough.ChartDecorator.java

public void initFileMenu(JMenu fileMenu) {
    super.initFileMenu(fileMenu);

    if (sampleInfos.size() > 0) {
        fileMenu.add(GuiUtils.makeMenuItem("Write data", this, "writeData"));
    }//from  ww w . jav a2  s .  co  m
}

From source file:hudson.lifecycle.WindowsSlaveInstaller.java

public Void call() {
    if (File.separatorChar == '/')
        return null; // not Windows
    if (System.getProperty("hudson.showWindowsServiceInstallLink") == null)
        return null; // only show this when it makes sense, which is when we run from JNLP

    dialog = MainDialog.get();/*from  w ww . j  av a  2  s. co  m*/
    if (dialog == null)
        return null; // can't find the main window. Maybe not running with GUI

    // capture the engine
    engine = Engine.current();

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            MainMenu mainMenu = dialog.getMainMenu();
            JMenu m = mainMenu.getFileMenu();
            JMenuItem menu = new JMenuItem(Messages.WindowsInstallerLink_DisplayName(), KeyEvent.VK_W);
            menu.addActionListener(WindowsSlaveInstaller.this);
            m.add(menu);
            mainMenu.commit();
        }
    });

    return null;
}

From source file:TopLevelTransferHandlerDemo.java

private JMenu createDummyMenu(String str) {
    JMenu menu = new JMenu(str);
    JMenuItem item = new JMenuItem("[Empty]");
    item.setEnabled(false);//from  w w  w .  j a  va 2 s .  c om
    menu.add(item);
    return menu;
}

From source file:MessageDigestTest.java

public MessageDigestFrame() {
    setTitle("MessageDigestTest");
    setSize(400, 200);//from www .j ava2s  . c  o m
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });

    JPanel panel = new JPanel();
    ButtonGroup group = new ButtonGroup();
    ActionListener listener = new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            JCheckBox b = (JCheckBox) event.getSource();
            setAlgorithm(b.getText());
        }
    };
    addCheckBox(panel, "SHA-1", group, true, listener);
    addCheckBox(panel, "MD5", group, false, listener);

    Container contentPane = getContentPane();

    contentPane.add(panel, "North");
    contentPane.add(new JScrollPane(message), "Center");
    contentPane.add(digest, "South");
    digest.setFont(new Font("Monospaced", Font.PLAIN, 12));

    setAlgorithm("SHA-1");

    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("File");
    JMenuItem fileDigestItem = new JMenuItem("File digest");
    fileDigestItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            loadFile();
        }
    });
    menu.add(fileDigestItem);
    JMenuItem textDigestItem = new JMenuItem("Text area digest");
    textDigestItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            String m = message.getText();
            computeDigest(m.getBytes());
        }
    });
    menu.add(textDigestItem);
    menuBar.add(menu);
    setJMenuBar(menuBar);
}

From source file:de.burrotinto.jKabel.dispalyAS.DisplayAAS.java

public DisplayAAS() {
    dbAuswahlAAS = JKabelS.getSpringContext().getBean(DBAuswahlAAS.class);

    setTitle("jKabel");

    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(south = getSouth(), BorderLayout.SOUTH);

    //File menue// ww w.  j av  a2  s  . c o  m
    JMenu menue = new JMenu("File");
    menue.add(edit);
    menue.add(search);

    menue.add(auchf);

    menue.addSeparator();
    menue.add(getjTypSortMenu());
    menue.add(getjTrommelSortMenu());
    menue.addSeparator();
    menue.add(exit);

    edit.addActionListener(this);
    search.addActionListener(this);
    exit.addActionListener(this);
    auchf.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            try {
                ConfigReader.getInstance().setZeigeAlle(auchf.isSelected());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });

    //License and more
    JMenu lMenue = new JMenu("Hilfe");
    lMenue.add(help);
    lMenue.add(gpl);

    help.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            new HelpAAS();
        }
    });
    gpl.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            new GPLAAS();
        }
    });

    // und zusammenbauen
    menuBar.add(menue);
    menuBar.add(lMenue);
    menuBar.add(new Version());

    // Trommelsuchband
    JMenuItem sbt = new JMenuItem("Suchen nach Trommelnummer");
    menuBar.add(sbt);
    sbt.addActionListener(JKabelS.getSpringContext().getBean(SearchTrommelNrAAS.class));
    JKabelS.getSpringContext().getBean(SearchTrommelNrAAS.class).setVisible(false);
    getContentPane().add(JKabelS.getSpringContext().getBean(SearchTrommelNrAAS.class), BorderLayout.NORTH);

    setJMenuBar(menuBar);

    IDBWrapper db = dbAuswahlAAS.getDBWrapper();

    bearbeitenPanel = (JPanel) JKabelS.getSpringContext().getBean("bearbeitenPanel");

    if (db == null) {
        center.add(new JLabel("Es konnte keine Verbindung zur DB hergestellt werden."));
        center.add(new JLabel(
                "Wenn !!!sicher!!! ist das kein anderer auf der DB arbeitet die lock.lck Datei lschen"));
        DisplayAAS d = this;
        getContentPane().add(center, BorderLayout.CENTER);
    } else {
        setDb(db);
    }

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    pack();
    setVisible(true);
}

From source file:be.nbb.demetra.dfm.output.FactorChart.java

private JMenu buildMenu() {
    JMenu result = new JMenu();

    result.add(new AbstractAction() {
        @Override/*from  www  .j  av  a2 s. c  o  m*/
        public void actionPerformed(ActionEvent e) {
            TsCollection col = TsFactory.instance.createTsCollection();
            col.add(TsFactory.instance.createTs("factor", null, data.factor));
            col.add(TsFactory.instance.createTs("filtered", null, data.filtered));
            col.add(TsFactory.instance.createTs("lower", null, data.lower));
            col.add(TsFactory.instance.createTs("upper", null, data.upper));
            Transferable t = TssTransferSupport.getInstance().fromTsCollection(col);
            Toolkit.getDefaultToolkit().getSystemClipboard().setContents(t, null);
        }
    }).setText("Copy all series");

    JMenu export = new JMenu("Export image to");
    export.add(ChartCommand.printImage().toAction(chartPanel)).setText("Printer...");
    export.add(ChartCommand.copyImage().toAction(chartPanel)).setText("Clipboard");
    export.add(ChartCommand.saveImage().toAction(chartPanel)).setText("File...");
    result.add(export);

    return result;
}

From source file:net.sf.housekeeper.swing.MainFrame.java

/**
 * Builds the menus.//  w w w. ja va 2s  .com
 * 
 * @return The created menu bar. Is not null.
 */
private JMenuBar buildMenuBar() {
    final JMenuBar menuBar = new JMenuBar();

    //File Menu
    final String fileMenuLabel = LocalisationManager.INSTANCE.getText("gui.menu.file");
    final JMenu menuFile = new JMenu(fileMenuLabel);
    menuBar.add(menuFile);

    menuFile.add(new JMenuItem(new LoadDataAction()));
    menuFile.add(new JMenuItem(new SaveDataAction()));
    menuFile.addSeparator();
    menuFile.add(new JMenuItem(new ExitAction()));

    //Help Menu
    final String helpMenuString = LocalisationManager.INSTANCE.getText("gui.menu.help");
    final JMenu menuHelp = new JMenu(helpMenuString);
    menuBar.add(Box.createHorizontalGlue());
    menuBar.add(menuHelp);

    menuHelp.add(new JMenuItem(new AboutDialogAction()));

    return menuBar;
}

From source file:ImageIOTest.java

public ImageIOFrame() {
    setTitle("ImageIOTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    JMenu fileMenu = new JMenu("File");
    JMenuItem openItem = new JMenuItem("Open");
    openItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            openFile();//from  www .j  a  v a  2s .  c  o m
        }
    });
    fileMenu.add(openItem);

    JMenu saveMenu = new JMenu("Save");
    fileMenu.add(saveMenu);
    Iterator<String> iter = writerFormats.iterator();
    while (iter.hasNext()) {
        final String formatName = iter.next();
        JMenuItem formatItem = new JMenuItem(formatName);
        saveMenu.add(formatItem);
        formatItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                saveFile(formatName);
            }
        });
    }

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

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