List of usage examples for javax.swing JMenu add
public JMenuItem add(Action a)
From source file:TextComponentDemo.java
protected JMenu createEditMenu() { JMenu menu = new JMenu("Edit"); // Undo and redo are actions of our own creation. undoAction = new UndoAction(); menu.add(undoAction); redoAction = new RedoAction(); menu.add(redoAction);//from w ww. j a va2s .c om menu.addSeparator(); // These actions come from the default editor kit. // Get the ones we want and stick them in the menu. menu.add(getActionByName(DefaultEditorKit.cutAction)); menu.add(getActionByName(DefaultEditorKit.copyAction)); menu.add(getActionByName(DefaultEditorKit.pasteAction)); menu.addSeparator(); menu.add(getActionByName(DefaultEditorKit.selectAllAction)); return menu; }
From source file:components.InternalFrameDemo.java
protected JMenuBar createMenuBar() { JMenuBar menuBar = new JMenuBar(); //Set up the lone menu. JMenu menu = new JMenu("Document"); menu.setMnemonic(KeyEvent.VK_D); menuBar.add(menu);//w ww. j a v a2s. co m //Set up the first menu item. JMenuItem menuItem = new JMenuItem("New"); menuItem.setMnemonic(KeyEvent.VK_N); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.ALT_MASK)); menuItem.setActionCommand("new"); menuItem.addActionListener(this); menu.add(menuItem); //Set up the second menu item. menuItem = new JMenuItem("Quit"); menuItem.setMnemonic(KeyEvent.VK_Q); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.ALT_MASK)); menuItem.setActionCommand("quit"); menuItem.addActionListener(this); menu.add(menuItem); return menuBar; }
From source file:uk.co.petertribble.jkstat.gui.KstatBaseChartFrame.java
/** * Create the File... Menu./*w w w .j a va 2s . c o m*/ * * @return the File Menu */ protected JMenu fileMenu() { JMenu jme = new JMenu(KstatResources.getString("FILE.TEXT")); jme.setMnemonic(KeyEvent.VK_F); saveItem = new JMenuItem(KstatResources.getString("FILE.SAVEAS.TEXT"), KeyEvent.VK_S); saveItem.addActionListener(this); jme.add(saveItem); jme.addSeparator(); exitItem = new JMenuItem(KstatResources.getString("FILE.CLOSE.TEXT"), KeyEvent.VK_C); exitItem.addActionListener(this); jme.add(exitItem); return jme; }
From source file:TopLevelTransferHandlerDemo.java
private JMenuBar createDummyMenuBar() { JMenuBar mb = new JMenuBar(); mb.add(createDummyMenu("File")); mb.add(createDummyMenu("Edit")); mb.add(createDummyMenu("Search")); mb.add(createDummyMenu("View")); mb.add(createDummyMenu("Tools")); mb.add(createDummyMenu("Help")); JMenu demo = new JMenu("Demo"); demo.setMnemonic(KeyEvent.VK_D); mb.add(demo);// w w w. j a va 2 s. c om thItem = new JCheckBoxMenuItem("Use Top-Level TransferHandler"); thItem.setMnemonic(KeyEvent.VK_T); demo.add(thItem); nullItem = new JCheckBoxMenuItem("Remove TransferHandler from List and Text"); nullItem.setMnemonic(KeyEvent.VK_R); demo.add(nullItem); copyItem = new JCheckBoxMenuItem("Use COPY Action"); copyItem.setMnemonic(KeyEvent.VK_C); demo.add(copyItem); return mb; }
From source file:ProgressMonitorInputStreamTest.java
public TextFrame() { setTitle("ProgressMonitorInputStreamTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); textArea = new JTextArea(); add(new JScrollPane(textArea)); chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar);//from w ww. ja v a 2 s. c o m JMenu fileMenu = new JMenu("File"); menuBar.add(fileMenu); openItem = new JMenuItem("Open"); openItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { openFile(); } catch (IOException exception) { exception.printStackTrace(); } } }); fileMenu.add(openItem); exitItem = new JMenuItem("Exit"); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); fileMenu.add(exitItem); }
From source file:eu.delving.sip.frames.AllFrames.java
public JMenu getViewMenu() { JMenu menu = new JMenu("View"); for (Action action : arrangements) menu.add(action); return menu;//from ww w . ja v a 2s.c om }
From source file:net.sf.jabref.gui.menus.RightClickMenu.java
public RightClickMenu(JabRefFrame frame, BasePanel panel) { this.panel = panel; JMenu typeMenu = new ChangeEntryTypeMenu().getChangeEntryTypeMenu(panel); // Are multiple entries selected? boolean multiple = areMultipleEntriesSelected(); // If only one entry is selected, get a reference to it for adapting the menu. BibEntry be = null;//from w ww.j a v a 2 s . c o m if (panel.getMainTable().getSelectedRowCount() == 1) { be = panel.getMainTable().getSelected().get(0); } addPopupMenuListener(this); JMenu copySpecialMenu = new JMenu(Localization.lang("Copy") + "..."); copySpecialMenu.add(new GeneralAction(Actions.COPY_KEY, Localization.lang("Copy BibTeX key"))); copySpecialMenu.add(new GeneralAction(Actions.COPY_CITE_KEY, Localization.lang("Copy \\cite{BibTeX key}"))); copySpecialMenu .add(new GeneralAction(Actions.COPY_KEY_AND_TITLE, Localization.lang("Copy BibTeX key and title"))); copySpecialMenu.add(new GeneralAction(Actions.EXPORT_TO_CLIPBOARD, Localization.lang("Export to clipboard"), IconTheme.JabRefIcon.EXPORT_TO_CLIPBOARD.getSmallIcon())); add(new GeneralAction(Actions.COPY, Localization.lang("Copy"), IconTheme.JabRefIcon.COPY.getSmallIcon())); add(copySpecialMenu); add(new GeneralAction(Actions.PASTE, Localization.lang("Paste"), IconTheme.JabRefIcon.PASTE.getSmallIcon())); add(new GeneralAction(Actions.CUT, Localization.lang("Cut"), IconTheme.JabRefIcon.CUT.getSmallIcon())); add(new GeneralAction(Actions.DELETE, Localization.lang("Delete"), IconTheme.JabRefIcon.DELETE_ENTRY.getSmallIcon())); addSeparator(); add(new GeneralAction(Actions.SEND_AS_EMAIL, Localization.lang("Send as email"), IconTheme.JabRefIcon.EMAIL.getSmallIcon())); addSeparator(); JMenu markSpecific = JabRefFrame.subMenu(Localization.menuTitle("Mark specific color")); for (int i = 0; i < EntryMarker.MAX_MARKING_LEVEL; i++) { markSpecific.add(new MarkEntriesAction(frame, i).getMenuItem()); } if (multiple) { add(new GeneralAction(Actions.MARK_ENTRIES, Localization.lang("Mark entries"), IconTheme.JabRefIcon.MARK_ENTRIES.getSmallIcon())); add(markSpecific); add(new GeneralAction(Actions.UNMARK_ENTRIES, Localization.lang("Unmark entries"), IconTheme.JabRefIcon.UNMARK_ENTRIES.getSmallIcon())); } else if (be != null) { Optional<String> marked = be.getFieldOptional(InternalBibtexFields.MARKED); // We have to check for "" too as the marked field may be empty if ((!marked.isPresent()) || marked.get().isEmpty()) { add(new GeneralAction(Actions.MARK_ENTRIES, Localization.lang("Mark entry"), IconTheme.JabRefIcon.MARK_ENTRIES.getSmallIcon())); add(markSpecific); } else { add(markSpecific); add(new GeneralAction(Actions.UNMARK_ENTRIES, Localization.lang("Unmark entry"), IconTheme.JabRefIcon.UNMARK_ENTRIES.getSmallIcon())); } } if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SPECIALFIELDSENABLED)) { if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_RANKING)) { JMenu rankingMenu = new JMenu(); RightClickMenu.populateSpecialFieldMenu(rankingMenu, Rank.getInstance(), frame); add(rankingMenu); } // TODO: multiple handling for relevance and quality-assurance // if multiple values are selected ("if (multiple)"), two options (set / clear) should be offered // if one value is selected either set or clear should be offered if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_RELEVANCE)) { add(Relevance.getInstance().getValues().get(0).getMenuAction(frame)); } if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_QUALITY)) { add(Quality.getInstance().getValues().get(0).getMenuAction(frame)); } if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_PRINTED)) { add(Printed.getInstance().getValues().get(0).getMenuAction(frame)); } if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_PRIORITY)) { JMenu priorityMenu = new JMenu(); RightClickMenu.populateSpecialFieldMenu(priorityMenu, Priority.getInstance(), frame); add(priorityMenu); } if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_READ)) { JMenu readStatusMenu = new JMenu(); RightClickMenu.populateSpecialFieldMenu(readStatusMenu, ReadStatus.getInstance(), frame); add(readStatusMenu); } } addSeparator(); add(new GeneralAction(Actions.OPEN_FOLDER, Localization.lang("Open folder")) { { if (!isFieldSetForSelectedEntry(FieldName.FILE)) { this.setEnabled(false); } } }); add(new GeneralAction(Actions.OPEN_EXTERNAL_FILE, Localization.lang("Open file"), getFileIconForSelectedEntry()) { { if (!isFieldSetForSelectedEntry(FieldName.FILE)) { this.setEnabled(false); } } }); add(new GeneralAction(Actions.OPEN_URL, Localization.lang("Open URL or DOI"), IconTheme.JabRefIcon.WWW.getSmallIcon()) { { if (!(isFieldSetForSelectedEntry(FieldName.URL) || isFieldSetForSelectedEntry(FieldName.DOI))) { this.setEnabled(false); } } }); addSeparator(); add(typeMenu); add(new GeneralAction(Actions.MERGE_DOI, Localization.lang("Get BibTeX data from DOI")) { { if (!(isFieldSetForSelectedEntry(FieldName.DOI))) { this.setEnabled(false); } } }); add(frame.getMassSetField()); add(new GeneralAction(Actions.ADD_FILE_LINK, Localization.lang("Attach file"), IconTheme.JabRefIcon.ATTACH_FILE.getSmallIcon())); add(frame.getManageKeywords()); add(new GeneralAction(Actions.MERGE_ENTRIES, Localization.lang("Merge entries") + "...", IconTheme.JabRefIcon.MERGE_ENTRIES.getSmallIcon()) { { if (!(areExactlyTwoEntriesSelected())) { this.setEnabled(false); } } }); addSeparator(); // for "add/move/remove to/from group" entries (appended here) groupAdd = new JMenuItem(new GeneralAction(Actions.ADD_TO_GROUP, Localization.lang("Add to group"))); add(groupAdd); groupRemove = new JMenuItem( new GeneralAction(Actions.REMOVE_FROM_GROUP, Localization.lang("Remove from group"))); add(groupRemove); groupMoveTo = add(new GeneralAction(Actions.MOVE_TO_GROUP, Localization.lang("Move to group"))); add(groupMoveTo); // create disabledIcons for all menu entries frame.createDisabledIconsForMenuEntries(this); }
From source file:ec.ui.view.MarginView.java
private JMenu buildMenu() { JMenu result = new JMenu(); result.add(new JCheckBoxMenuItem(new AbstractAction() { @Override//from w ww .j av a 2s .c o m public void actionPerformed(ActionEvent e) { setPrecisionMarkersVisible(!isPrecisionMarkersVisible()); } })).setText("Show precision gradient"); result.add(new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { TsCollection col = TsFactory.instance.createTsCollection(); col.add(TsFactory.instance.createTs("series", null, data.series)); col.add(TsFactory.instance.createTs("lower", null, data.lower)); col.add(TsFactory.instance.createTs("upper", null, data.upper)); Transferable t = TssTransferSupport.getDefault().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:DragColorTextFieldDemo.java
public JMenuBar createMenuBar() { JMenuItem menuItem = null;/*from ww w. ja va 2 s .c o m*/ JMenuBar menuBar = new JMenuBar(); JMenu mainMenu = new JMenu("Edit"); mainMenu.setMnemonic(KeyEvent.VK_E); menuItem = new JMenuItem(new DefaultEditorKit.CutAction()); menuItem.setText("Cut"); menuItem.setMnemonic(KeyEvent.VK_T); mainMenu.add(menuItem); menuItem = new JMenuItem(new DefaultEditorKit.CopyAction()); menuItem.setText("Copy"); menuItem.setMnemonic(KeyEvent.VK_C); mainMenu.add(menuItem); menuItem = new JMenuItem(new DefaultEditorKit.PasteAction()); menuItem.setText("Paste"); menuItem.setMnemonic(KeyEvent.VK_P); mainMenu.add(menuItem); menuBar.add(mainMenu); return menuBar; }
From source file:ToolbarDemo.java
protected JMenuBar createMenuBar() { final JMenuBar menuBar = new JMenuBar(); JMenu mFile = new JMenu("File"); mFile.setMnemonic('f'); ImageIcon iconNew = new ImageIcon("file_new.gif"); Action actionNew = new AbstractAction("New", iconNew) { public void actionPerformed(ActionEvent e) { System.out.println("new action"); }//from www .j a va 2 s.c o m }; JMenuItem item = mFile.add(actionNew); mFile.add(item); ImageIcon iconOpen = new ImageIcon("file_open.gif"); Action actionOpen = new AbstractAction("Open...", iconOpen) { public void actionPerformed(ActionEvent e) { System.out.println("open action"); } }; item = mFile.add(actionOpen); mFile.add(item); ImageIcon iconSave = new ImageIcon("file_save.gif"); Action actionSave = new AbstractAction("Save...", iconSave) { public void actionPerformed(ActionEvent e) { System.out.println("save action"); } }; item = mFile.add(actionSave); mFile.add(item); mFile.addSeparator(); Action actionExit = new AbstractAction("Exit") { public void actionPerformed(ActionEvent e) { System.exit(0); } }; item = mFile.add(actionExit); item.setMnemonic('x'); menuBar.add(mFile); toolBar = new JToolBar(); JButton btn1 = toolBar.add(actionNew); btn1.setToolTipText("New text"); JButton btn2 = toolBar.add(actionOpen); btn2.setToolTipText("Open text file"); JButton btn3 = toolBar.add(actionSave); btn3.setToolTipText("Save text file"); ActionListener fontListener = new ActionListener() { public void actionPerformed(ActionEvent e) { updateMonitor(); } }; JMenu mFont = new JMenu("Font"); mFont.setMnemonic('o'); ButtonGroup group = new ButtonGroup(); fontMenus = new JMenuItem[FontNames.length]; for (int k = 0; k < FontNames.length; k++) { int m = k + 1; fontMenus[k] = new JRadioButtonMenuItem(m + " " + FontNames[k]); boolean selected = (k == 0); fontMenus[k].setSelected(selected); fontMenus[k].setMnemonic('1' + k); fontMenus[k].setFont(fonts[k]); fontMenus[k].addActionListener(fontListener); group.add(fontMenus[k]); mFont.add(fontMenus[k]); } mFont.addSeparator(); boldMenu.setMnemonic('b'); Font fn = fonts[1].deriveFont(Font.BOLD); boldMenu.setFont(fn); boldMenu.setSelected(false); boldMenu.addActionListener(fontListener); mFont.add(boldMenu); italicMenu.setMnemonic('i'); fn = fonts[1].deriveFont(Font.ITALIC); italicMenu.setFont(fn); italicMenu.setSelected(false); italicMenu.addActionListener(fontListener); mFont.add(italicMenu); menuBar.add(mFont); getContentPane().add(toolBar, BorderLayout.NORTH); return menuBar; }