List of usage examples for javax.swing JMenu add
public JMenuItem add(Action a)
From source file:au.org.ala.delta.editor.DeltaEditor.java
private JMenuBar buildMenus() { JMenuBar menuBar = new JMenuBar(); // File menu. This on is kind of special, in that it gets rebuilt each // time a file is opened. _fileMenu = new JMenu(); _fileMenu.setName("mnuFile"); buildFileMenu(_fileMenu);//w w w . j a v a 2s . c o m menuBar.add(_fileMenu); // Edit Menu JMenu mnuEdit = buildEditMenu(); menuBar.add(mnuEdit); // Search Menu JMenu mnuSearch = buildSearchMenu(); menuBar.add(mnuSearch); // View Menu JMenu mnuView = buildViewMenu(); menuBar.add(mnuView); // Window menu _windowMenu = new JMenu(); _windowMenu.setName("mnuWindow"); buildWindowMenu(_windowMenu); menuBar.add(_windowMenu); JMenu mnuHelp = new JMenu(); mnuHelp.setName("mnuHelp"); JMenuItem mnuItHelpContents = new JMenuItem(); mnuItHelpContents.setName("mnuItHelpContents"); mnuHelp.add(mnuItHelpContents); mnuItHelpContents.addActionListener(_helpController.helpAction()); JMenuItem mnuItHelpOnSelection = new JMenuItem(IconHelper.createImageIcon("help_cursor.png")); mnuItHelpOnSelection.setName("mnuItHelpOnSelection"); mnuItHelpOnSelection.addActionListener(_helpController.helpOnSelectionAction()); mnuHelp.add(mnuItHelpOnSelection); javax.swing.Action openAboutAction = _actionMap.get("openAbout"); if (isMac()) { configureMacAboutBox(openAboutAction); } else { JMenuItem mnuItAbout = new JMenuItem(); mnuItAbout.setAction(openAboutAction); mnuHelp.addSeparator(); mnuHelp.add(mnuItAbout); } menuBar.add(mnuHelp); return menuBar; }
From source file:com.sshtools.common.ui.SshToolsApplicationPanel.java
public void addFavorite(StandardAction action) { for (int i = 0; i < menuBar.getMenuCount(); i++) { JMenu menu = menuBar.getMenu(i); if (menu.getText() != null && menu.getText().equals("Favorites")) { menu.add(action); }/*w w w . ja v a 2 s. co m*/ } }
From source file:edu.clemson.cs.nestbed.client.gui.TestbedManagerFrame.java
private final JMenu buildFileMenu() { JMenu file = new JMenu("File"); JMenuItem exit = new JMenuItem("Exit"); exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { doExit();/*w ww.j av a2 s. c om*/ } }); file.add(exit); return file; }
From source file:net.sf.jabref.gui.plaintextimport.TextInputDialog.java
private void initPopupMenuAndToolbar() { // copy/paste Menu PasteAction pasteAction = new PasteAction(); ClearAction clearAction = new ClearAction(); JMenuItem pasteMI = new JMenuItem(pasteAction); inputMenu.add(clearAction);//from ww w .ja v a 2 s. c om inputMenu.addSeparator(); inputMenu.add(pasteMI); inputMenu.addSeparator(); // Right-click append/override JMenu appendMenu = new JMenu(Localization.lang("Append")); appendMenu.setToolTipText(Localization.lang("Append the selected text to BibTeX field")); JMenu overrideMenu = new JMenu(Localization.lang("Override")); overrideMenu.setToolTipText(Localization.lang("Override the BibTeX field by the selected text")); for (String field : allFields) { appendMenu.add(new JMenuItem(new MenuTextForTagAction(field, false))); overrideMenu.add(new JMenuItem(new MenuTextForTagAction(field, true))); } inputMenu.add(appendMenu); inputMenu.add(overrideMenu); // Toolbar toolBar.add(clearAction); toolBar.setBorderPainted(false); toolBar.addSeparator(); toolBar.add(pasteAction); toolBar.add(new LoadAction()); }
From source file:de.burrotinto.jKabel.dispalyAS.DisplayAAS.java
private JMenu getjTypSortMenu() { JMenu typSortMenu = new JMenu("Typ Sortierung"); JRadioButtonMenuItem inOrder = new JRadioButtonMenuItem("Aufsteigend Sortieren"); inOrder.setSelected(ConfigReader.getInstance().isTypeInOrder()); inOrder.addActionListener(new ActionListener() { @Override/* ww w . ja v a2 s . co m*/ public void actionPerformed(ActionEvent actionEvent) { try { ConfigReader.getInstance().setTypeInOrder(inOrder.isSelected()); // if (kabelTypAuswahlAAS != null) { // kabelTypAuswahlAAS.typSelected(kabelTypAuswahlAAS.getSelected()); // } } catch (IOException e) { e.printStackTrace(); } } }); typSortMenu.add(inOrder); typSortMenu.addSeparator(); ButtonGroup group = new ButtonGroup(); for (AbstractTypeSort aTS : ConfigReader.getInstance().getAllTypSort()) { JRadioButtonMenuItem sw = new JRadioButtonMenuItem(aTS.getName()); sw.setSelected(aTS.equals(ConfigReader.getInstance().getKabeltypSort())); group.add(sw); typSortMenu.add(sw); sw.addActionListener(aTS); } return typSortMenu; }
From source file:com.github.lindenb.jvarkit.tools.bamviewgui.BamFileRef.java
BamFrame(List<BamFileRef> BamFileRefs) { super((JFrame) null, "Bam View (" + BamFileRefs.size() + " files)", ModalityType.APPLICATION_MODAL); this.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); this.BamFileRefs = BamFileRefs; addWindowListener(new WindowAdapter() { @Override//from w ww . j av a 2s . c om public void windowOpened(WindowEvent e) { removeWindowListener(this); Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); d.width -= 150; d.height -= 150; for (BamFileRef vfr : BamFrame.this.BamFileRefs) { LOG.info("Reading " + vfr.bamFile); int w = (int) (d.width * 0.8); int h = (int) (d.height * 0.8); BamInternalFrame iFrame = new BamInternalFrame(vfr); iFrame.setBounds(Math.max((int) ((d.width - w) * Math.random()), 0), Math.max((int) ((d.height - h) * Math.random()), 0), w, h); desktopPane.add(iFrame); BamInternalFrames.add(iFrame); iFrame.setVisible(true); iFrame.jTable.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { JTable t = (JTable) e.getSource(); int row = t.getSelectedRow(); if (row == -1) return; BamTableModel tm = (BamTableModel) t.getModel(); showIgv(tm.getValueAt(row, 0), tm.getValueAt(row, 1)); } } }); } reloadFrameContent(); } }); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { doMenuClose(); } }); JMenuBar bar = new JMenuBar(); setJMenuBar(bar); JMenu menu = new JMenu("File"); bar.add(menu); menu.add(new AbstractAction("Quit") { @Override public void actionPerformed(ActionEvent e) { doMenuClose(); } }); menu = new JMenu("Flags"); bar.add(menu); for (SamFlag flag : SamFlag.values()) { JCheckBox cbox = new JCheckBox("Require " + flag); requiredFlags.add(cbox); menu.add(cbox); } menu.add(new JSeparator()); for (SamFlag flag : SamFlag.values()) { JCheckBox cbox = new JCheckBox("Filter out " + flag); filteringFlags.add(cbox); menu.add(cbox); } JPanel contentPane = new JPanel(new BorderLayout(5, 5)); setContentPane(contentPane); this.desktopPane = new JDesktopPane(); contentPane.add(this.desktopPane, BorderLayout.CENTER); JPanel top = new JPanel(new FlowLayout(FlowLayout.LEADING)); contentPane.add(top, BorderLayout.NORTH); JLabel lbl = new JLabel("Max Rows:", JLabel.LEADING); JSpinner spinner = new JSpinner(this.numFetchModel = new SpinnerNumberModel(100, 1, 10000, 10)); lbl.setLabelFor(spinner); top.add(lbl); top.add(spinner); lbl = new JLabel("Timeout (secs):", JLabel.LEADING); spinner = new JSpinner(this.numSecondsModel = new SpinnerNumberModel(2, 1, 10000, 1)); lbl.setLabelFor(spinner); top.add(lbl); top.add(spinner); //lbl=new JLabel("JEXL:",JLabel.LEADING); /*jexlField=new JTextField(20); lbl.setLabelFor(jexlField); top.add(lbl); top.add(jexlField);*/ lbl = new JLabel("Region:", JLabel.LEADING); selectRgnField = new JTextField(20); lbl.setLabelFor(selectRgnField); AbstractAction action = new AbstractAction("Select") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent a) { if ( /* (jexlField.getText().trim().isEmpty() || parseJex(jexlField.getText().trim())!=null) && */ (selectRgnField.getText().trim().isEmpty() || parseOne(selectRgnField.getText()) != null)) { reloadFrameContent(); } else { LOG.info("Bad input " + selectRgnField.getText()); } } }; selectRgnField.addActionListener(action); //jexlField.addActionListener(action); top.add(lbl); top.add(selectRgnField); top.add(new JButton(action)); }
From source file:au.org.ala.delta.editor.DeltaEditor.java
private void buildWindowMenu(JMenu mnuWindow) { mnuWindow.removeAll();/* www. j a v a 2s . c o m*/ JMenuItem mnuItCascade = new JMenuItem(); mnuItCascade.setAction(_actionMap.get("cascadeFrames")); mnuWindow.add(mnuItCascade); JMenuItem mnuItTile = new JMenuItem(); mnuItTile.setAction(_actionMap.get("tileFrames")); mnuWindow.add(mnuItTile); JMenuItem mnuItTileHorz = new JMenuItem(); mnuItTileHorz.setAction(_actionMap.get("tileFramesHorizontally")); mnuWindow.add(mnuItTileHorz); JMenuItem mnuItArrangeIcons = new JMenuItem(); mnuItArrangeIcons.setAction(_actionMap.get("arrangeIcons")); mnuWindow.add(mnuItArrangeIcons); JMenuItem mnuItCloseAll = new JMenuItem(); mnuItCloseAll.setAction(_actionMap.get("closeAllFrames")); mnuWindow.add(mnuItCloseAll); mnuWindow.addSeparator(); JMenuItem mnuItChooseFont = new JMenuItem(); mnuItChooseFont.setAction(_actionMap.get("chooseFont")); mnuWindow.add(mnuItChooseFont); mnuWindow.addSeparator(); JMenu mnuLF = new JMenu(); mnuLF.setName("mnuLF"); mnuLF.setText(_resourceMap.getString("mnuLF.text")); mnuWindow.add(mnuLF); JMenuItem mnuItMetalLF = new JMenuItem(); mnuItMetalLF.setAction(_actionMap.get("metalLookAndFeel")); mnuLF.add(mnuItMetalLF); JMenuItem mnuItWindowsLF = new JMenuItem(); mnuItWindowsLF.setAction(_actionMap.get("systemLookAndFeel")); mnuLF.add(mnuItWindowsLF); try { // Nimbus L&F was added in update java 6 update 10. Class.forName("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel").newInstance(); JMenuItem mnuItNimbusLF = new JMenuItem(); mnuItNimbusLF.setAction(_actionMap.get("nimbusLookAndFeel")); mnuLF.add(mnuItNimbusLF); } catch (Exception e) { // The Nimbus L&F is not available, no matter. } mnuWindow.addSeparator(); int i = 1; for (final JInternalFrame frame : _frames) { JMenuItem windowItem = new JCheckBoxMenuItem(); if (i < 10) { windowItem.setText(String.format("%d %s", i, frame.getTitle())); windowItem.setMnemonic(KeyEvent.VK_1 + (i - 1)); } else { windowItem.setText(frame.getTitle()); } windowItem.setSelected(frame.isSelected()); windowItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { frame.setSelected(true); } catch (PropertyVetoException e1) { } } }); mnuWindow.add(windowItem); ++i; } }
From source file:MenuSelectionManagerDemo.java
public JMenuBar createMenuBar() { JMenuBar menuBar;// w w w.j a v a2 s . c om JMenu menu, submenu; JMenuItem menuItem; JRadioButtonMenuItem rbMenuItem; JCheckBoxMenuItem cbMenuItem; //Create the menu bar. menuBar = new JMenuBar(); //Build the first menu. menu = new JMenu("A Menu"); menu.setMnemonic(KeyEvent.VK_A); menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items"); menuBar.add(menu); //a group of JMenuItems menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T); //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything"); menuItem.addActionListener(this); menu.add(menuItem); ImageIcon icon = createImageIcon("1.gif"); menuItem = new JMenuItem("Both text and icon", icon); menuItem.setMnemonic(KeyEvent.VK_B); menuItem.addActionListener(this); menu.add(menuItem); menuItem = new JMenuItem(icon); menuItem.setMnemonic(KeyEvent.VK_D); menuItem.addActionListener(this); menu.add(menuItem); //a group of radio button menu items menu.addSeparator(); ButtonGroup group = new ButtonGroup(); rbMenuItem = new JRadioButtonMenuItem("A radio button menu item"); rbMenuItem.setSelected(true); rbMenuItem.setMnemonic(KeyEvent.VK_R); group.add(rbMenuItem); rbMenuItem.addActionListener(this); menu.add(rbMenuItem); rbMenuItem = new JRadioButtonMenuItem("Another one"); rbMenuItem.setMnemonic(KeyEvent.VK_O); group.add(rbMenuItem); rbMenuItem.addActionListener(this); menu.add(rbMenuItem); //a group of check box menu items menu.addSeparator(); cbMenuItem = new JCheckBoxMenuItem("A check box menu item"); cbMenuItem.setMnemonic(KeyEvent.VK_C); cbMenuItem.addItemListener(this); menu.add(cbMenuItem); cbMenuItem = new JCheckBoxMenuItem("Another one"); cbMenuItem.setMnemonic(KeyEvent.VK_H); cbMenuItem.addItemListener(this); menu.add(cbMenuItem); //a submenu menu.addSeparator(); submenu = new JMenu("A submenu"); submenu.setMnemonic(KeyEvent.VK_S); menuItem = new JMenuItem("An item in the submenu"); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK)); menuItem.addActionListener(this); submenu.add(menuItem); menuItem = new JMenuItem("Another item"); menuItem.addActionListener(this); submenu.add(menuItem); menu.add(submenu); //Build second menu in the menu bar. menu = new JMenu("Another Menu"); menu.setMnemonic(KeyEvent.VK_N); menu.getAccessibleContext().setAccessibleDescription("This menu does nothing"); menuBar.add(menu); Timer timer = new Timer(ONE_SECOND, new ActionListener() { public void actionPerformed(ActionEvent evt) { MenuElement[] path = MenuSelectionManager.defaultManager().getSelectedPath(); for (int i = 0; i < path.length; i++) { if (path[i].getComponent() instanceof javax.swing.JMenuItem) { JMenuItem mi = (JMenuItem) path[i].getComponent(); if ("".equals(mi.getText())) { output.append("ICON-ONLY MENU ITEM > "); } else { output.append(mi.getText() + " > "); } } } if (path.length > 0) output.append(newline); } }); timer.start(); return menuBar; }
From source file:de.burrotinto.jKabel.dispalyAS.DisplayAAS.java
private JMenu getjTrommelSortMenu() { JMenu trommelSortMenu = new JMenu("Trommel Sortierung"); JRadioButtonMenuItem inOrder = new JRadioButtonMenuItem("Aufsteigend Sortieren"); inOrder.setSelected(ConfigReader.getInstance().isTypeInOrder()); inOrder.addActionListener(new ActionListener() { @Override/* ww w. j ava 2 s . co m*/ public void actionPerformed(ActionEvent actionEvent) { try { ConfigReader.getInstance().setTrommelInOrder(inOrder.isSelected()); // if (kabelTypAuswahlAAS != null) { // kabelTypAuswahlAAS.typSelected(kabelTypAuswahlAAS.getSelected()); // } } catch (IOException e) { e.printStackTrace(); } } }); trommelSortMenu.add(inOrder); trommelSortMenu.addSeparator(); ButtonGroup group = new ButtonGroup(); for (AbstractTrommelSort aTS : ConfigReader.getInstance().getAllTrommelSort()) { JRadioButtonMenuItem sw = new JRadioButtonMenuItem(aTS.getName()); sw.setSelected(aTS.equals(ConfigReader.getInstance().getTrommelSort())); group.add(sw); trommelSortMenu.add(sw); sw.addActionListener(aTS); } return trommelSortMenu; }
From source file:ffx.ui.MainMenu.java
private Action addMenuItem(JMenu menu, String icon, String actionCommand, int mnemonic, int accelerator, final ActionListener actionListener) { Action a = new AbstractAction() { @Override/* www . jav a 2 s . c o m*/ public void actionPerformed(ActionEvent e) { actionListener.actionPerformed(e); } }; configureAction(a, icon, actionCommand, mnemonic, accelerator); JMenuItem menuItem = new JMenuItem(a); menu.add(menuItem); return a; }