List of usage examples for javax.swing JMenu add
public JMenuItem add(Action a)
From source file:com.github.rholder.gradle.ui.DependencyViewerStandalone.java
private void initMenu() { JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic(KeyEvent.VK_F); menuBar.add(fileMenu);/*ww w. j ava2 s . c o m*/ JMenuItem open = new JMenuItem("Open Project Folder", KeyEvent.VK_O); open.setMnemonic(KeyEvent.VK_O); open.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { promptForGradleBaseDir(); refresh(); } }); fileMenu.add(open); JMenuItem refresh = new JMenuItem("Refresh"); refresh.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { refresh(); } }); fileMenu.add(refresh); fileMenu.addSeparator(); JMenuItem exit = new JMenuItem("Exit", KeyEvent.VK_X); exit.setMnemonic(KeyEvent.VK_X); exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); fileMenu.add(exit); setJMenuBar(menuBar); }
From source file:misc.ActionDemo.java
protected JMenu createAbleMenu() { JMenu ableMenu = new JMenu("Action State"); cbmi = new JCheckBoxMenuItem[3]; cbmi[0] = new JCheckBoxMenuItem("First action enabled"); cbmi[1] = new JCheckBoxMenuItem("Second action enabled"); cbmi[2] = new JCheckBoxMenuItem("Third action enabled"); for (int i = 0; i < cbmi.length; i++) { cbmi[i].setSelected(true);//from w ww . j a v a2 s. c om cbmi[i].addItemListener(this); ableMenu.add(cbmi[i]); } return ableMenu; }
From source file:de.codesourcery.jasm16.ide.ui.MenuManager.java
protected JMenuBar createMenuBar() { final List<MenuEntry> copy; synchronized (entriesList) { copy = new ArrayList<MenuEntry>(entriesList); }//from w ww . j av a 2 s. co m // collect distinct parent paths final List<MenuPath> paths = new ArrayList<MenuPath>(); for (MenuEntry e : copy) { if (!e.isVisible()) { continue; } final MenuPath parentPath = e.getPath().getParentPath(); if (parentPath == null) { continue; } for (MenuPath p : parentPath.getAllPaths()) { if (!paths.contains(p)) { paths.add(p); } } } // sort paths ascending by length Collections.sort(paths, new Comparator<MenuPath>() { @Override public int compare(MenuPath o1, MenuPath o2) { final int len1 = o1.toString().length(); final int len2 = o2.toString().length(); if (len1 < len2) { return -1; } else if (len1 > len2) { return 1; } return 0; } }); /* * - a * | * +-- b * | * + c */ // create menu for each path final Map<MenuPath, JMenu> menuesByPath = new HashMap<MenuPath, JMenu>(); for (MenuPath path : paths) { final JMenu menu = new JMenu(path.getLastPathComponent()); menuesByPath.put(path, menu); JMenu parentMenu = menuesByPath.get(path.getParentPath()); if (parentMenu != null) { parentMenu.add(menu); } } // setup menu bar //Where the GUI is created: final JMenuBar menuBar = new JMenuBar(); final Set<MenuPath> topLevelMenues = new HashSet<MenuPath>(); for (final MenuEntry e : copy) { if (!e.isVisible()) { continue; } final MenuPath parentPath = e.getPath().getParentPath(); final JMenu menu = menuesByPath.get(parentPath); if (menu == null) { throw new RuntimeException("Internal error, failed to create menu for path: " + e.getPath()); } // register top-level menues if (parentPath.length() == 1) { if (!topLevelMenues.contains(parentPath)) { menuBar.add(menu); topLevelMenues.add(parentPath); } } final Action action; action = new AbstractAction(e.getLabel()) { @Override public void actionPerformed(ActionEvent event) { e.onClick(); } @Override public boolean isEnabled() { return e.isEnabled(); } }; final JMenuItem item = new JMenuItem(action) { @Override public boolean isEnabled() { return action.isEnabled(); } }; if (e.hasMnemonic()) { item.setMnemonic(e.getMnemonic()); } e.setMenuItem(item); menu.add(item); } return menuBar; }
From source file:edu.clemson.cs.nestbed.client.gui.MessageMonitorFrame.java
private JMenu buildFileMenu() { JMenu menu = new JMenu("File"); JMenuItem close = new JMenuItem("Close"); close.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { MessageMonitorFrame.this.setVisible(false); }/*from w w w .j a v a2 s .co m*/ }); menu.add(close); return menu; }
From source file:de.hstsoft.sdeep.view.MainWindow.java
private void createUI() { mapView = new MapView(); getContentPane().add(mapView, BorderLayout.CENTER); JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar);//from w w w . j a v a 2s .c om JMenu mnFile = new JMenu("File"); menuBar.add(mnFile); JMenuItem mntmOpenSaveGame = new JMenuItem("Open Savegame"); mntmOpenSaveGame.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { openFileChooser(); } }); mnFile.add(mntmOpenSaveGame); mnFile.addSeparator(); JMenuItem mntmExit = new JMenuItem("Exit"); mntmExit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); mnFile.add(mntmExit); JMenu mnView = new JMenu("View"); menuBar.add(mnView); final JCheckBoxMenuItem menuItemShowinfo = new JCheckBoxMenuItem("ShowInfo"); menuItemShowinfo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { boolean showInfo = menuItemShowinfo.isSelected(); mapView.setShowInfo(showInfo); } }); menuItemShowinfo.setSelected(mapView.isShowInfo()); mnView.add(menuItemShowinfo); final JCheckBoxMenuItem menuItemShowgrid = new JCheckBoxMenuItem("ShowGrid"); menuItemShowgrid.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { boolean showGrid = menuItemShowgrid.isSelected(); mapView.setShowGrid(showGrid); } }); menuItemShowgrid.setSelected(mapView.isShowGrid()); mnView.add(menuItemShowgrid); final JCheckBoxMenuItem menuItemNotes = new JCheckBoxMenuItem("ShowNotes"); menuItemNotes.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { boolean showNotes = menuItemNotes.isSelected(); mapView.setShowNotes(showNotes); } }); menuItemNotes.setSelected(mapView.isShowNotes()); mnView.add(menuItemNotes); final JCheckBoxMenuItem menuItemAnimals = new JCheckBoxMenuItem("ShowAnimals"); menuItemAnimals.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { boolean showAnimals = menuItemAnimals.isSelected(); mapView.setShowAnimals(showAnimals); } }); menuItemAnimals.setSelected(mapView.isShowAnimals()); mnView.add(menuItemAnimals); mnView.addSeparator(); menuItemFileWatcher = new JCheckBoxMenuItem("Auto refresh"); menuItemFileWatcher.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { boolean enabled = menuItemFileWatcher.isSelected(); toggleAutoRefresh(enabled); } }); mnView.add(menuItemFileWatcher); mnView.addSeparator(); JMenuItem menuItemResetView = new JMenuItem("Reset view"); menuItemResetView.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { mapView.resetView(); } }); mnView.add(menuItemResetView); JMenu mnInfo = new JMenu("Info"); menuBar.add(mnInfo); JMenuItem mntmInfo = new JMenuItem("About"); mntmInfo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { showInfo(); } }); mnInfo.add(mntmInfo); }
From source file:org.jax.maanova.fit.gui.ResidualPlotPanel.java
@SuppressWarnings("serial") private JMenuBar createMenu() { JMenuBar menuBar = new JMenuBar(); // the file menu JMenu fileMenu = new JMenu("File"); fileMenu.add(this.saveGraphImageAction); menuBar.add(fileMenu);//from w w w .j a v a 2 s . c o m // the tools menu JMenu toolsMenu = new JMenu("Tools"); JMenuItem configureGraphItem = new JMenuItem("Configure Graph..."); configureGraphItem.addActionListener(new ActionListener() { /** * {@inheritDoc} */ public void actionPerformed(ActionEvent e) { ResidualPlotPanel.this.chartConfigurationDialog.setVisible(true); } }); toolsMenu.add(configureGraphItem); toolsMenu.addSeparator(); toolsMenu.add(new AbstractAction("Zoom Out") { /** * {@inheritDoc} */ public void actionPerformed(ActionEvent e) { ResidualPlotPanel.this.autoRangeChart(); } }); toolsMenu.addSeparator(); JCheckBoxMenuItem showTooltipCheckbox = new JCheckBoxMenuItem("Show Info Popup for Nearest Point"); showTooltipCheckbox.setSelected(true); this.showTooltip = true; showTooltipCheckbox.addItemListener(new ItemListener() { /** * {@inheritDoc} */ public void itemStateChanged(ItemEvent e) { ResidualPlotPanel.this.showTooltip = e.getStateChange() == ItemEvent.SELECTED; ResidualPlotPanel.this.clearProbePopup(); } }); toolsMenu.add(showTooltipCheckbox); menuBar.add(toolsMenu); // the help menu JMenu helpMenu = new JMenu("Help"); JMenuItem helpMenuItem = new JMenuItem("Help...", new ImageIcon(ResidualPlotAction.class.getResource("/images/action/help-16x16.png"))); helpMenuItem.addActionListener(new ActionListener() { /** * {@inheritDoc} */ public void actionPerformed(ActionEvent e) { Maanova.getInstance().showHelp("residual-plot", ResidualPlotPanel.this); } }); helpMenu.add(helpMenuItem); menuBar.add(helpMenu); return menuBar; }
From source file:PrintCanvas3D.java
private JMenuBar createMenuBar() { JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); printItem = new JMenuItem("Print..."); printItem.addActionListener(this); closeItem = new JMenuItem("Close"); closeItem.addActionListener(this); fileMenu.add(printItem); fileMenu.add(new JSeparator()); fileMenu.add(closeItem);/*from ww w . j a v a 2s.c o m*/ menuBar.add(fileMenu); return menuBar; }
From source file:net.sf.mzmine.chartbasics.gui.swing.EChartPanel.java
/** * Adds the GraphicsExportDialog menu and the data export menu *///from w w w . j a v a 2 s . c om protected void addExportMenu(boolean graphics, boolean data) { this.getPopupMenu().addSeparator(); if (graphics) { // Graphics Export ChartExportUtil.addExportDialogToMenu(this); } if (data) { // General data export JMenu export = new JMenu("Export data ..."); // Excel XY JMenuExportToExcel exportXY = new JMenuExportToExcel(new XSSFExcelWriterReader(), "to Excel", this); export.add(exportXY); // clip board JMenuExportToClipboard exportXYClipboard = new JMenuExportToClipboard("to Clipboard", this); export.add(exportXYClipboard); // add to panel addPopupMenu(export); } }
From source file:org.jax.maanova.madata.gui.ArrayScatterPlotPanel.java
@SuppressWarnings("serial") private JMenuBar createMenu() { JMenuBar menuBar = new JMenuBar(); // the file menu JMenu fileMenu = new JMenu("File"); fileMenu.add(this.saveGraphImageAction); menuBar.add(fileMenu);//from ww w .ja v a2 s. co m // the tools menu JMenu toolsMenu = new JMenu("Tools"); JMenuItem configureGraphItem = new JMenuItem("Configure Graph..."); configureGraphItem.addActionListener(new ActionListener() { /** * {@inheritDoc} */ public void actionPerformed(ActionEvent e) { ArrayScatterPlotPanel.this.chartConfigurationDialog.setVisible(true); } }); toolsMenu.add(configureGraphItem); toolsMenu.addSeparator(); toolsMenu.add(new AbstractAction("Zoom Out") { /** * {@inheritDoc} */ public void actionPerformed(ActionEvent e) { ArrayScatterPlotPanel.this.autoRangeChart(); } }); JCheckBoxMenuItem showTooltipCheckbox = new JCheckBoxMenuItem("Show Info Popup for Nearest Point"); showTooltipCheckbox.setSelected(true); this.showTooltip = true; showTooltipCheckbox.addItemListener(new ItemListener() { /** * {@inheritDoc} */ public void itemStateChanged(ItemEvent e) { ArrayScatterPlotPanel.this.showTooltip = e.getStateChange() == ItemEvent.SELECTED; ArrayScatterPlotPanel.this.clearProbePopup(); } }); toolsMenu.add(showTooltipCheckbox); menuBar.add(toolsMenu); // the help menu JMenu helpMenu = new JMenu("Help"); JMenuItem helpMenuItem = new JMenuItem("Help..."); Icon helpIcon = new ImageIcon(ArrayScatterPlotPanel.class.getResource("/images/action/help-16x16.png")); helpMenuItem.setIcon(helpIcon); helpMenuItem.addActionListener(new ActionListener() { /** * {@inheritDoc} */ public void actionPerformed(ActionEvent e) { Maanova.getInstance().showHelp("array-scatter-plot", ArrayScatterPlotPanel.this); } }); helpMenu.add(helpMenuItem); menuBar.add(helpMenu); return menuBar; }
From source file:com.alvermont.javascript.tools.shell.ShellJSConsole.java
public ShellJSConsole(String[] args) { super("Rhino JavaScript Console"); final JMenuBar menubar = new JMenuBar(); createFileChooser();/*from w ww. j a v a 2s. c o m*/ final String[] fileItems = { "Load...", "Close" }; final String[] fileCmds = { "Load", "Close" }; final char[] fileShortCuts = { 'L', 'X' }; final String[] editItems = { "Cut", "Copy", "Paste" }; final char[] editShortCuts = { 'T', 'C', 'P' }; final JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic('F'); final JMenu editMenu = new JMenu("Edit"); editMenu.setMnemonic('E'); for (int i = 0; i < fileItems.length; ++i) { final JMenuItem item = new JMenuItem(fileItems[i], fileShortCuts[i]); item.setActionCommand(fileCmds[i]); item.addActionListener(this); fileMenu.add(item); } for (int i = 0; i < editItems.length; ++i) { final JMenuItem item = new JMenuItem(editItems[i], editShortCuts[i]); item.addActionListener(this); editMenu.add(item); } final ButtonGroup group = new ButtonGroup(); menubar.add(fileMenu); menubar.add(editMenu); setJMenuBar(menubar); this.consoleTextArea = new ShellConsoleTextArea(args); final JScrollPane scroller = new JScrollPane(this.consoleTextArea); setContentPane(scroller); this.consoleTextArea.setRows(24); this.consoleTextArea.setColumns(80); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { setVisible(false); } }); pack(); setVisible(true); // System.setIn(consoleTextArea.getIn()); // System.setOut(consoleTextArea.getOut()); // System.setErr(consoleTextArea.getErr()); ShellMain.setIn(this.consoleTextArea.getIn()); ShellMain.setOut(this.consoleTextArea.getOut()); ShellMain.setErr(this.consoleTextArea.getErr()); // we don't do this here as we want to separate construction from // the run thread this.args = args; //ShellMain.exec(args); }