List of usage examples for javax.swing JMenu JMenu
public JMenu(Action a)
Action
supplied. From source file:SiteFrame.java
public PageFrame(String name, SiteManager sm) { super("Page: " + name, true, true, true, true); parent = sm;/*from ww w .ja va2s. c om*/ setBounds(50, 50, 300, 150); Container contentPane = getContentPane(); // Create a text area to display the contents of our file in // and stick it in a scrollable pane so we can see everything ta = new JTextArea(); JScrollPane jsp = new JScrollPane(ta); contentPane.add(jsp, BorderLayout.CENTER); JMenuBar jmb = new JMenuBar(); JMenu fileMenu = new JMenu("File"); JMenuItem saveItem = new JMenuItem("Save"); saveItem.addActionListener(this); fileMenu.add(saveItem); jmb.add(fileMenu); setJMenuBar(jmb); filename = name; loadContent(); }
From source file:net.erdfelt.android.sdkfido.ui.SdkFidoFrame.java
private JMenu createViewMenu() { JMenu viewMenu = new JMenu("View"); viewMenu.setMnemonic('v'); JMenu lnfMenu = new JMenu("Look and Feel"); lnfMenu.setMnemonic('f'); ButtonGroup lnfGroup = new ButtonGroup(); LookAndFeelInfo lnfs[] = UIManager.getInstalledLookAndFeels(); String lnfCurrentName = null; LookAndFeel lnfCurrent = UIManager.getLookAndFeel(); if (lnfCurrent != null) { lnfCurrentName = lnfCurrent.getClass().getName(); }//from w w w.java 2 s. c om UISwitcher switcher = new UISwitcher(); for (int i = 0; i < lnfs.length; i++) { JRadioButtonMenuItem lnfItem = new JRadioButtonMenuItem(lnfs[i].getName()); lnfItem.addActionListener(switcher); lnfItem.setActionCommand(lnfs[i].getClassName()); lnfGroup.add(lnfItem); lnfMenu.add(lnfItem); if (lnfs[i].getClassName().equals(lnfCurrentName)) { lnfGroup.setSelected(lnfItem.getModel(), true); } } viewMenu.add(lnfMenu); return viewMenu; }
From source file:gdt.jgui.entity.fields.JFieldsEditor.java
/** * Get the context menu.//from ww w . j ava 2 s . c om * @return the context menu. */ @Override public JMenu getContextMenu() { menu = new JMenu("Context"); menu.addMenuListener(new MenuListener() { @Override public void menuSelected(MenuEvent e) { // System.out.println("FieldsEditor:getConextMenu:menu selected"); if (editCellItem != null) menu.remove(editCellItem); if (deleteItemsItem != null) menu.remove(deleteItemsItem); if (copyItem != null) menu.remove(copyItem); if (pasteItem != null) menu.remove(pasteItem); if (cutItem != null) menu.remove(cutItem); if (hasEditingCell()) { editCellItem = new JMenuItem("Edit item"); editCellItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { JTextEditor textEditor = new JTextEditor(); String locator$ = textEditor.getLocator(); locator$ = Locator.append(locator$, Entigrator.ENTIHOME, entihome$); locator$ = Locator.append(locator$, EntityHandler.ENTITY_KEY, entityKey$); String responseLocator$ = getEditCellLocator(); text$ = Locator.getProperty(responseLocator$, JTextEditor.TEXT); locator$ = Locator.append(locator$, JTextEditor.TEXT, text$); // System.out.println("FieldsEditor:edit cell:text="+text$); locator$ = Locator.append(locator$, JRequester.REQUESTER_RESPONSE_LOCATOR, Locator.compressText(responseLocator$)); JConsoleHandler.execute(console, locator$); } catch (Exception ee) { LOGGER.severe(ee.toString()); } } }); menu.add(editCellItem); } if (hasSelectedRows()) { deleteItemsItem = new JMenuItem("Delete items"); deleteItemsItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int response = JOptionPane.showConfirmDialog(JFieldsEditor.this, "Delete selected fields ?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.YES_OPTION) { deleteRows(); } } }); menu.add(deleteItemsItem); copyItem = new JMenuItem("Copy"); copyItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { copy(false); } }); menu.add(copyItem); cutItem = new JMenuItem("Cut"); cutItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { copy(true); } }); menu.add(cutItem); } if (hasFieldsToPaste()) { pasteItem = new JMenuItem("Paste"); pasteItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { String[] sa = console.clipboard.getContent(); Properties locator; String type$; String sourceEntityKey$; Sack sourceEntity; String sourceEntihome$; Entigrator sourceEntigrator; for (String aSa : sa) { //System.out.println("FieldsEditor:paste:"+aSa); locator = Locator.toProperties(aSa); type$ = locator.getProperty(Locator.LOCATOR_TYPE); if (LOCATOR_TYPE_FIELD.equals(type$)) { String action$ = locator.getProperty(JRequester.REQUESTER_ACTION); String name$ = locator.getProperty(CELL_FIELD_NAME); String value$ = locator.getProperty(CELL_FIELD_VALUE); if (name$ != null) { if (ACTION_COPY_FIELDS.equals(action$)) entity.putElementItem("field", new Core(null, name$, value$)); if (ACTION_CUT_FIELDS.equals(action$)) { entity.putElementItem("field", new Core(null, name$, value$)); sourceEntihome$ = locator.getProperty(Entigrator.ENTIHOME); sourceEntigrator = console.getEntigrator(sourceEntihome$); sourceEntityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY); sourceEntity = sourceEntigrator.getEntityAtKey(sourceEntityKey$); sourceEntity.removeElementItem("field", name$); sourceEntigrator.save(sourceEntity); } } } } entigrator.save(entity); Core[] ca = entity.elementGet("field"); replaceTable(ca); } catch (Exception ee) { LOGGER.info(ee.toString()); } } }); menu.add(pasteItem); } } @Override public void menuDeselected(MenuEvent e) { } @Override public void menuCanceled(MenuEvent e) { } }); doneItem = new JMenuItem("Done"); doneItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { save(); if (requesterResponseLocator$ != null) { try { byte[] ba = Base64.decodeBase64(requesterResponseLocator$); String responseLocator$ = new String(ba, "UTF-8"); responseLocator$ = Locator.append(responseLocator$, Entigrator.ENTIHOME, entihome$); responseLocator$ = Locator.append(responseLocator$, EntityHandler.ENTITY_KEY, entityKey$); // System.out.println("FieldsEditor:done.response locator="+responseLocator$); JConsoleHandler.execute(console, responseLocator$); } catch (Exception ee) { LOGGER.severe(ee.toString()); } } else console.back(); } }); menu.add(doneItem); JMenuItem cancelItem = new JMenuItem("Cancel"); cancelItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { console.back(); } }); menu.add(cancelItem); menu.addSeparator(); JMenuItem addItemItem = new JMenuItem("Add item"); addItemItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { addRow(); } }); menu.add(addItemItem); if (postMenu != null) { //System.out.println("JFieldsEditor:postMenu="+postMenu.length); for (JMenuItem jmi : postMenu) menu.add(jmi); } //else // System.out.println("JFieldsEditor:postMenu empty"); return menu; }
From source file:com.haulmont.cuba.desktop.sys.MenuBuilder.java
private void createSubMenu(JMenu jMenu, MenuItem item) { List<MenuItem> itemChildren = new ArrayList<>(item.getChildren()); CollectionUtils.filter(itemChildren, object -> object.isPermitted(userSession)); List<MenuItemContainer> items = new ArrayList<>(); // prepare menu items for (MenuItem child : itemChildren) { if (child.getChildren().isEmpty()) { if (child.isSeparator()) { items.add(new MenuItemContainer()); } else { JMenuItem jMenuItem = new JMenuItem(menuConfig.getItemCaption(child.getId())); jMenuItem.setName(child.getId()); assignCommand(jMenuItem, child); assignShortcut(jMenuItem, child); items.add(new MenuItemContainer(jMenuItem)); }/*from w w w. ja va 2s. co m*/ } else { JMenu jChildMenu = new JMenu(menuConfig.getItemCaption(child.getId())); createSubMenu(jChildMenu, child); if (!isMenuEmpty(jChildMenu)) { items.add(new MenuItemContainer(jChildMenu)); } } } // remove unnecessary separators if (!items.isEmpty()) { Iterator<MenuItemContainer> iterator = items.iterator(); JMenuItem menuItem = getNextMenuItem(iterator); boolean useSeparator = false; while (menuItem != null) { if (useSeparator) jMenu.addSeparator(); jMenu.add(menuItem); useSeparator = false; menuItem = null; if (iterator.hasNext()) { MenuItemContainer itemContainer = iterator.next(); if (!itemContainer.isSeparator()) menuItem = itemContainer.getMenuItem(); else { menuItem = getNextMenuItem(iterator); useSeparator = true; } } } } }
From source file:gdt.jgui.entity.procedure.JProcedurePanel.java
/** * Get the context menu.//from w w w . j ava 2 s . com * @return the context menu. */ @Override public JMenu getContextMenu() { menu = new JMenu("Context"); menu.addMenuListener(new MenuListener() { @Override public void menuSelected(MenuEvent e) { menu.removeAll(); JMenuItem runItem = new JMenuItem("Run"); runItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { run(); } }); menu.add(runItem); Entigrator entigrator = console.getEntigrator(entihome$); Sack procedure = entigrator.getEntityAtKey(entityKey$); if (procedure.getElementItem("parameter", "noreset") == null) { JMenuItem resetItem = new JMenuItem("Reset"); resetItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int response = JOptionPane.showConfirmDialog(console.getContentPanel(), "Reset source to default ?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.YES_OPTION) reset(); } }); menu.add(resetItem); } JMenuItem folderItem = new JMenuItem("Open folder"); folderItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { File file = new File(entihome$ + "/" + entityKey$); Desktop.getDesktop().open(file); } catch (Exception ee) { Logger.getLogger(getClass().getName()).info(ee.toString()); } } }); menu.add(folderItem); try { //Entigrator entigrator=console.getEntigrator(entihome$); Sack entity = entigrator.getEntityAtKey(entityKey$); String template$ = entity.getAttributeAt("template"); if (template$ != null) { JMenuItem adaptClone = new JMenuItem("Adapt clone"); adaptClone.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { adaptClone(console, getLocator()); } catch (Exception ee) { Logger.getLogger(getClass().getName()).info(ee.toString()); } } }); menu.add(adaptClone); } } catch (Exception ee) { Logger.getLogger(getClass().getName()).info(ee.toString()); } } @Override public void menuDeselected(MenuEvent e) { } @Override public void menuCanceled(MenuEvent e) { } }); return menu; }
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 ww w . j a v a 2 s. c o m }); menu.add(close); return menu; }
From source file:com.quattroresearch.antibody.plugin.PluginLoader.java
/** * Loads the menu plugins and inserts them into the menu. *///from ww w. j av a 2 s . c o m 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:adams.gui.tools.FileMonitorPanel.java
/** * Creates a menu bar (singleton per panel object). Can be used in frames. * * @return the menu bar//from w w w.j a va2 s . c om */ @Override public JMenuBar getMenuBar() { JMenuBar result; JMenu menu; JMenu submenu; JMenuItem menuitem; if (m_MenuBar == null) { result = new JMenuBar(); // File menu = new JMenu("File"); result.add(menu); menu.setMnemonic('F'); menu.addChangeListener((ChangeEvent e) -> updateMenu()); menuitem = new JMenuItem("Open...", GUIHelper.getIcon("open.gif")); menuitem.setMnemonic('O'); menuitem.setAccelerator(GUIHelper.getKeyStroke("ctrl pressed O")); menuitem.addActionListener((ActionEvent e) -> open()); menu.add(menuitem); m_MenuItemOpen = menuitem; // File/Recent files submenu = new JMenu("Open recent"); menu.add(submenu); m_RecentFilesHandler = new RecentFilesHandler<>(SESSION_FILE, 5, submenu); m_RecentFilesHandler.addRecentItemListener(new RecentItemListener<JMenu, File>() { public void recentItemAdded(RecentItemEvent<JMenu, File> e) { // ignored } public void recentItemSelected(RecentItemEvent<JMenu, File> e) { open(e.getItem()); } }); m_MenuItemOpenRecent = submenu; menu.addSeparator(); menuitem = new JMenuItem("Close", GUIHelper.getIcon("exit.png")); menuitem.setMnemonic('C'); menuitem.setAccelerator(GUIHelper.getKeyStroke("ctrl pressed Q")); menuitem.addActionListener((ActionEvent e) -> close()); menu.add(menuitem); m_MenuItemClose = menuitem; // update menu m_MenuBar = result; updateMenu(); } else { result = m_MenuBar; } return result; }
From source file:com.prodigy4440.view.MainJFrame.java
public final void initComponents() { List<Image> icons = new LinkedList<>(); icons.add(new ImageIcon(getClass().getResource("/com/prodigy4440/ited16x16.png")).getImage()); icons.add(new ImageIcon(getClass().getResource("/com/prodigy4440/ited32x32.png")).getImage()); icons.add(new ImageIcon(getClass().getResource("/com/prodigy4440/ited48x48.png")).getImage()); icons.add(new ImageIcon(getClass().getResource("/com/prodigy4440/ited72x72.png")).getImage()); this.setIconImages(icons); ActionHandler actionHandler = new ActionHandler(this); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setSize(620, 520); this.setLocationRelativeTo(null); this.setTitle("Untitled Document- IgboTextEditor"); southJPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); SoftBevelBorder sbb = new SoftBevelBorder(SoftBevelBorder.LOWERED); southJPanel.setBorder(sbb);//from w w w .j av a2s. c o m menuBar = new JMenuBar(); fileJMenu = new JMenu("File"); fileJMenu.setMnemonic('F'); editJMenu = new JMenu("Edit"); editJMenu.setMnemonic('E'); formatJMenu = new JMenu("Format"); formatJMenu.setMnemonic('A'); viewJMenu = new JMenu("View"); viewJMenu.setMnemonic('V'); helpJMenu = new JMenu("Help"); helpJMenu.setMnemonic('H'); newDocumentJMenuItem = new JMenuItem("New"); newDocumentJMenuItem.addActionListener(actionHandler); newDocumentJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, Event.CTRL_MASK)); openJMenuItem = new JMenuItem("Open"); openJMenuItem.addActionListener(actionHandler); openJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, Event.CTRL_MASK)); saveJMenuItem = new JMenuItem("Save"); saveJMenuItem.addActionListener(actionHandler); saveJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.CTRL_MASK)); printJMenuItem = new JMenuItem("Print"); printJMenuItem.addActionListener(actionHandler); printJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, Event.CTRL_MASK)); exitJMenuItem = new JMenuItem("Exit"); exitJMenuItem.addActionListener(actionHandler); undoJMenuItem = new JMenuItem("Undo"); undoJMenuItem.addActionListener(actionHandler); undoJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, Event.CTRL_MASK)); redoJMenuItem = new JMenuItem("Redo"); redoJMenuItem.addActionListener(actionHandler); redoJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Y, Event.CTRL_MASK)); copyJMenuItem = new JMenuItem("Copy"); copyJMenuItem.addActionListener(actionHandler); copyJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, Event.CTRL_MASK)); cutJMenuItem = new JMenuItem("Cut"); cutJMenuItem.addActionListener(actionHandler); cutJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, Event.CTRL_MASK)); pasteJMenuItem = new JMenuItem("Paste"); pasteJMenuItem.addActionListener(actionHandler); pasteJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, Event.CTRL_MASK)); deleteJMenuItem = new JMenuItem("Delete"); deleteJMenuItem.addActionListener(actionHandler); deleteJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, Event.CTRL_MASK)); selectAllJMenuItem = new JMenuItem("Select All"); selectAllJMenuItem.addActionListener(actionHandler); selectAllJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, Event.CTRL_MASK)); findJMenuItem = new JMenuItem("Find"); findJMenuItem.addActionListener(actionHandler); findJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, Event.CTRL_MASK)); replaceJMenuItem = new JMenuItem("Replace"); replaceJMenuItem.addActionListener(actionHandler); replaceJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, Event.CTRL_MASK)); wordWrapJCheckBoxMenuItem = new JCheckBoxMenuItem("Word Wrap"); wordWrapJCheckBoxMenuItem.addActionListener(actionHandler); wordWrapJCheckBoxMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, Event.CTRL_MASK)); fontJMenuItem = new JMenuItem("Font"); fontJMenuItem.addActionListener(actionHandler); colorJMenuItem = new JMenuItem("Color"); colorJMenuItem.addActionListener(actionHandler); statusBarJCheckBoxMenuItem = new JCheckBoxMenuItem("Status Bar"); statusBarJCheckBoxMenuItem.addActionListener(actionHandler); statusBarJCheckBoxMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.ALT_MASK)); helpJMenuItem = new JMenuItem("Help"); helpJMenuItem.addActionListener(actionHandler); helpJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, Event.CTRL_MASK)); aboutJMenuItem = new JMenuItem("About"); aboutJMenuItem.addActionListener(actionHandler); statusJLabel = new JLabel("Status:"); //Main text area setup textArea = new JTextArea(); undoManager = new UndoManager(); wordSearcher = new WordSearcher(textArea); textArea.setBorder(BorderFactory.createMatteBorder(4, 4, 4, 4, Color.WHITE)); document = textArea.getDocument(); document.addUndoableEditListener(new UndoableEditListener() { @Override public void undoableEditHappened(UndoableEditEvent e) { undoManager.addEdit(e.getEdit()); } }); font = new Font("Tahoma", Font.PLAIN, 16); textArea.setFont(font); color = Color.BLUE; textArea.setForeground(color); undoManager = new UndoManager(); fileJMenu.add(newDocumentJMenuItem); fileJMenu.addSeparator(); fileJMenu.add(openJMenuItem); fileJMenu.add(saveJMenuItem); fileJMenu.addSeparator(); fileJMenu.add(printJMenuItem); fileJMenu.addSeparator(); fileJMenu.add(exitJMenuItem); editJMenu.add(undoJMenuItem); editJMenu.add(redoJMenuItem); editJMenu.addSeparator(); editJMenu.add(copyJMenuItem); editJMenu.add(cutJMenuItem); editJMenu.add(pasteJMenuItem); editJMenu.addSeparator(); editJMenu.add(deleteJMenuItem); editJMenu.add(selectAllJMenuItem); editJMenu.addSeparator(); editJMenu.add(findJMenuItem); editJMenu.add(replaceJMenuItem); formatJMenu.add(wordWrapJCheckBoxMenuItem); formatJMenu.add(fontJMenuItem); formatJMenu.add(colorJMenuItem); viewJMenu.add(statusBarJCheckBoxMenuItem); helpJMenu.add(helpJMenuItem); helpJMenu.add(aboutJMenuItem); menuBar.add(fileJMenu); menuBar.add(editJMenu); menuBar.add(formatJMenu); menuBar.add(viewJMenu); menuBar.add(helpJMenu); southJPanel.setVisible(false); southJPanel.add(statusJLabel); //JScrollPane setup JScrollPane scrollPane = new JScrollPane(textArea); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); //setting uo the Jframe this.setJMenuBar(menuBar); this.add(scrollPane, BorderLayout.CENTER); this.add(southJPanel, BorderLayout.SOUTH); textArea.addMouseListener(new MouseInputListener() { @Override public void mouseClicked(MouseEvent e) { Highlighter h = textArea.getHighlighter(); h.removeAllHighlights(); } @Override public void mousePressed(MouseEvent e) { Highlighter h = textArea.getHighlighter(); h.removeAllHighlights(); } @Override public void mouseReleased(MouseEvent e) { } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mouseDragged(MouseEvent e) { } @Override public void mouseMoved(MouseEvent e) { } }); textArea.addKeyListener(new IgboKeyListener(textArea)); }