List of usage examples for javax.swing JMenu removeAll
public void removeAll()
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar bar = new JMenuBar(); JMenu menu = new JMenu("File"); ComponentOrientation ori = ComponentOrientation.LEFT_TO_RIGHT; menu.applyComponentOrientation(ori); bar.add(menu);// w ww. j a va2 s . co m menu.add(new JMenuItem("Close")); menu.add(new JSeparator()); // SEPARATOR JMenuItem item = new JMenuItem("Exit"); menu.add(item); setJMenuBar(bar); add(new JLabel("A placeholder")); pack(); setSize(300, 300); setVisible(true); menu.removeAll(); }
From source file:ca.sqlpower.swingui.object.VariablesPanel.java
@SuppressWarnings("unchecked") private void showVarsPicker() { final MultiValueMap namespaces = this.variableHelper.getNamespaces(); List<String> sortedNames = new ArrayList<String>(namespaces.keySet().size()); sortedNames.addAll(namespaces.keySet()); Collections.sort(sortedNames, new Comparator<String>() { public int compare(String o1, String o2) { if (o1 == null) { return -1; }//from www . j av a 2s. c om if (o2 == null) { return 1; } return o1.compareTo(o2); }; }); final JPopupMenu menu = new JPopupMenu(); for (final String name : sortedNames) { final JMenu subMenu = new JMenu(name); menu.add(subMenu); subMenu.addMenuListener(new MenuListener() { private Timer timer; public void menuSelected(MenuEvent e) { subMenu.removeAll(); subMenu.add(new PleaseWaitAction()); ActionListener menuPopulator = new ActionListener() { public void actionPerformed(ActionEvent e) { if (subMenu.isPopupMenuVisible()) { subMenu.removeAll(); for (Object namespaceO : namespaces.getCollection(name)) { String namespace = (String) namespaceO; logger.debug("Resolving variables for namespace ".concat(namespace)); int nbItems = 0; for (String key : variableHelper.keySet(namespace)) { subMenu.add(new InsertVariableAction(SPVariableHelper.getKey((String) key), (String) key)); nbItems++; } if (nbItems == 0) { subMenu.add(new DummyAction()); logger.debug("No variables found."); } } subMenu.revalidate(); subMenu.getPopupMenu().pack(); } } }; timer = new Timer(700, menuPopulator); timer.setRepeats(false); timer.start(); } public void menuDeselected(MenuEvent e) { timer.stop(); } public void menuCanceled(MenuEvent e) { timer.stop(); } }); } menu.show(varNameText, 0, varNameText.getHeight()); }
From source file:br.org.acessobrasil.ases.ferramentas_de_reparo.vista.corretor_eventos.PanelCorretorEventos.java
/** * Recria o menu editar do Frame Principal * /*w ww.ja va 2 s .c om*/ * @param menu * @return */ private JMenu criaMenuEditar(JMenu menu) { menu.removeAll(); menu.setMnemonic('E'); menu.setMnemonic(KeyEvent.VK_E); menu.add(new JMenuItemTeclaAtalho(textAreaSourceCode)); menu.add(new JSeparator()); JMenuItem btnContraste = new JMenuItem(XHTML_Panel.ALTERAR_CONTRASTE); btnContraste.addActionListener(this); btnContraste.setActionCommand("Contraste"); // btnAumenta.setMnemonic('F'); // btnAumenta.setMnemonic(KeyEvent.VK_F); // btnAumenta.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ADD, // ActionEvent.CTRL_MASK)); btnContraste.setToolTipText(XHTML_Panel.DICA_CONTRASTE); btnContraste.getAccessibleContext().setAccessibleDescription(XHTML_Panel.DICA_CONTRASTE); menu.add(btnContraste); JMenuItem btnAumenta = new JMenuItem(XHTML_Panel.AUMENTA_FONTE); btnAumenta.addActionListener(this); btnAumenta.setActionCommand("AumentaFonte"); // btnAumenta.setMnemonic('F'); // btnAumenta.setMnemonic(KeyEvent.VK_F); btnAumenta.setAccelerator( javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ADD, ActionEvent.CTRL_MASK)); btnAumenta.setToolTipText(XHTML_Panel.DICA_AUMENTA_FONTE); btnAumenta.getAccessibleContext().setAccessibleDescription(XHTML_Panel.DICA_AUMENTA_FONTE); menu.add(btnAumenta); JMenuItem btnDiminui = new JMenuItem(XHTML_Panel.DIMINUI_FONTE); btnDiminui.addActionListener(this); btnDiminui.setActionCommand("DiminuiFonte"); // btnDiminui.setMnemonic('F'); // btnDiminui.setMnemonic(KeyEvent.VK_F); btnDiminui.setAccelerator( javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_SUBTRACT, ActionEvent.CTRL_MASK)); btnDiminui.setToolTipText(XHTML_Panel.DICA_DIMINUI_FONTE); btnDiminui.getAccessibleContext().setAccessibleDescription(XHTML_Panel.DICA_DIMINUI_FONTE); menu.add(btnDiminui); menu.add(new JSeparator()); JMenuItem btnProcurar = new JMenuItem(XHTML_Panel.PROCURAR); btnProcurar.addActionListener(this); btnProcurar.setActionCommand("Procurar"); btnProcurar.setMnemonic('P'); btnProcurar.setMnemonic(KeyEvent.VK_P); btnProcurar.setAccelerator( javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, ActionEvent.CTRL_MASK)); btnProcurar.setToolTipText(XHTML_Panel.DICA_PROCURAR); btnProcurar.getAccessibleContext().setAccessibleDescription(XHTML_Panel.DICA_PROCURAR); menu.add(btnProcurar); JMenuItem btnSelecionarTudo = new JMenuItem(XHTML_Panel.SELECIONAR_TUDO); btnSelecionarTudo.addActionListener(this); btnSelecionarTudo.setActionCommand("SelecionarTudo"); btnSelecionarTudo.setMnemonic('T'); btnSelecionarTudo.setMnemonic(KeyEvent.VK_T); btnSelecionarTudo.setAccelerator( javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, ActionEvent.CTRL_MASK)); btnSelecionarTudo.setToolTipText(XHTML_Panel.DICA_SELECIONAR_TUDO); btnSelecionarTudo.getAccessibleContext().setAccessibleDescription(XHTML_Panel.DICA_SELECIONAR_TUDO); menu.add(btnSelecionarTudo); JMenuItem btnDesfazer = new JMenuItem(XHTML_Panel.DESFAZER); btnDesfazer.addActionListener(this); btnDesfazer.setActionCommand("Desfazer"); btnDesfazer.setMnemonic('z'); btnDesfazer.setMnemonic(KeyEvent.VK_Z); btnDesfazer.setAccelerator( javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Z, ActionEvent.CTRL_MASK)); btnDesfazer.setToolTipText(XHTML_Panel.DICA_DESFAZER); btnDesfazer.getAccessibleContext().setAccessibleDescription(XHTML_Panel.DICA_DESFAZER); menu.add(btnDesfazer); return menu; }
From source file:gdt.jgui.entity.contact.JContactEditor.java
@Override public JMenu getContextMenu() { final JMenu menu = new JMenu("Context"); menu.addMenuListener(new MenuListener() { @Override// w w w. j av a 2s. c om public void menuSelected(MenuEvent e) { // System.out.println("EntityEditor:getConextMenu:menu selected"); menu.removeAll(); JMenuItem facetsItem = new JMenuItem("Facets"); facetsItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { save(); JEntityFacetPanel erm = new JEntityFacetPanel(); String locator$ = erm.getLocator(); locator$ = Locator.append(locator$, Entigrator.ENTIHOME, entihome$); locator$ = Locator.append(locator$, EntityHandler.ENTITY_KEY, entityKey$); JConsoleHandler.execute(console, locator$); } }); menu.add(facetsItem); JMenuItem digestItem = new JMenuItem("Digest"); digestItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { save(); String locator$ = getLocator(); JEntityDigestDisplay edd = new JEntityDigestDisplay(); edd.instantiate(console, locator$); String eddLocator$ = edd.getLocator(); eddLocator$ = Locator.append(eddLocator$, Entigrator.ENTIHOME, entihome$); eddLocator$ = Locator.append(eddLocator$, EntityHandler.ENTITY_KEY, entityKey$); JConsoleHandler.execute(console, eddLocator$); } }); menu.add(digestItem); JMenuItem structureItem = new JMenuItem("Structure"); structureItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { save(); String locator$ = getLocator(); JEntityStructurePanel esp = new JEntityStructurePanel(); esp.instantiate(console, locator$); String espLocator$ = esp.getLocator(); espLocator$ = Locator.append(espLocator$, Entigrator.ENTIHOME, entihome$); espLocator$ = Locator.append(espLocator$, EntityHandler.ENTITY_KEY, entityKey$); JConsoleHandler.execute(console, espLocator$); } }); menu.add(structureItem); menu.addSeparator(); JMenuItem doneItem = new JMenuItem("Done"); doneItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { Entigrator entigrator = console.getEntigrator(entihome$); Sack contact = entigrator.getEntityAtKey(entityKey$); String entityLabel$ = contact.getProperty("label"); String title$ = title.getText(); if (!entityLabel$.equals(title$)) { contact = entigrator.ent_assignLabel(contact, title$); contact = entigrator.ent_assignProperty(contact, "contact", contact.getProperty("label")); } contact = entigrator.ent_assignProperty(contact, "phone", phone.getText()); contact = entigrator.ent_assignProperty(contact, "email", email.getText()); if (requesterResponseLocator$ != null) { byte[] ba = Base64.decodeBase64(requesterResponseLocator$); String responseLocator$ = new String(ba, "UTF-8"); // System.out.println("TextEditor:done:response locator="+responseLocator$); JConsoleHandler.execute(console, responseLocator$); } else console.back(); } catch (Exception ee) { Logger.getLogger(JContactEditor.class.getName()).severe(ee.toString()); } } }); menu.add(doneItem); JMenuItem cancelItem = new JMenuItem("Cancel"); cancelItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { console.back(); } }); menu.add(cancelItem); } @Override public void menuDeselected(MenuEvent e) { // TODO Auto-generated method stub } @Override public void menuCanceled(MenuEvent e) { // TODO Auto-generated method stub } }); return menu; }
From source file:ee.ioc.cs.vsle.editor.Editor.java
/** * @param menu//from w ww . j a v a 2 s . c o m */ private void makeRecentSubMenu(JMenu menu) { menu.removeAll(); for (final Map.Entry<String, String> entry : RuntimeProperties.getRecentPackages().entrySet()) { JMenuItem menuItem = new JMenuItem(entry.getKey()); menuItem.setToolTipText(entry.getValue()); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { openNewCanvasWithPackage(new File(entry.getValue())); } }); menu.add(menuItem); } }
From source file:ee.ioc.cs.vsle.editor.Editor.java
/** * @param menu/* w ww .j av a 2 s . c o m*/ */ private void makeSchemeMenu(JMenu menu) { menu.removeAll(); // Specification... JMenuItem menuItem = new JMenuItem(Menu.SPECIFICATION, KeyEvent.VK_S); menuItem.addActionListener(getActionListener()); menu.add(menuItem); //Extend menuItem = new JMenuItem(Menu.EXTEND_SPEC, KeyEvent.VK_E); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menu.add(new JSeparator()); // Run menuItem = new JMenuItem(Menu.RUN, KeyEvent.VK_R); menuItem.addActionListener(getActionListener()); menu.add(menuItem); //Propagate menuItem = new JCheckBoxMenuItem(Menu.PROPAGATE_VALUES, RuntimeProperties.isPropagateValues()); menuItem.addActionListener(getActionListener()); menu.add(menuItem); //Compute goal menuItem = new JCheckBoxMenuItem(Menu.COMPUTE_GOAL, RuntimeProperties.isComputeGoal()); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menu.add(new JSeparator()); // Values menuItem = new JMenuItem(Menu.SCHEME_VALUES, KeyEvent.VK_V); menuItem.addActionListener(getActionListener()); boolean enabled = getCurrentCanvas() != null && getCurrentCanvas().getLastProgramRunnerID() != 0; menuItem.setEnabled(enabled); if (!enabled) menuItem.setToolTipText("Run the scheme first"); menu.add(menuItem); menu.add(new JSeparator()); // Options menuItem = new JMenuItem(Menu.SCHEMEOPTIONS, KeyEvent.VK_O); menuItem.addActionListener(getActionListener()); menu.add(menuItem); }
From source file:au.org.ala.delta.editor.DeltaEditor.java
private void buildFileMenu(JMenu mnuFile) { mnuFile.removeAll(); String[] fileMenuActions = { "newFile", "loadFile", "closeFile", "-", "saveFile", "saveAsFile", "-", "importDirectives", "exportDirectives" }; MenuBuilder.buildMenu(mnuFile, fileMenuActions, _actionMap); mnuFile.addSeparator();/*from w ww. j a va2 s.c o m*/ String[] previous = EditorPreferences.getPreviouslyUsedFiles(); if (previous != null && previous.length > 0) { javax.swing.Action a = this._actionMap.get("loadPreviousFile"); if (a != null) { for (int i = 0; i < previous.length; ++i) { String filename = previous[i]; JMenuItem item = new JMenuItem(); item.setAction(a); item.setText(String.format("%d %s", i + 1, filename)); item.putClientProperty("Filename", filename); item.setMnemonic(KeyEvent.VK_1 + i); mnuFile.add(item); } } } if (!isMac()) { mnuFile.addSeparator(); JMenuItem mnuItFileExit = new JMenuItem(); mnuItFileExit.setAction(_actionMap.get("exitApplication")); mnuFile.add(mnuItFileExit); } }
From source file:au.org.ala.delta.editor.DeltaEditor.java
private void buildWindowMenu(JMenu mnuWindow) { mnuWindow.removeAll(); JMenuItem mnuItCascade = new JMenuItem(); mnuItCascade.setAction(_actionMap.get("cascadeFrames")); mnuWindow.add(mnuItCascade);/*from w w w.ja v a 2 s .com*/ 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:com.opendoorlogistics.studio.appframe.AppFrame.java
private void initFileMenu(JMenu mnFile, List<? extends Action> fileActions, ActionFactory actionFactory, MenuFactory menuBuilder) {/* www.j a v a 2 s .c om*/ mnFile.removeAll(); // non-dynamic for (Action action : fileActions) { if (action == null) { mnFile.addSeparator(); } else { mnFile.add(action); // if (action.accelerator != null) { // item.setAccelerator(action.accelerator); // } } } // import (not in action list as doesn't appear on toolbar) mnFile.addSeparator(); JMenu mnImport = menuBuilder.createImportMenu(this); mnFile.add(mnImport); // dynamic mnFile.addSeparator(); for (AppFrameAction action : actionFactory.createLoadRecentFilesActions(this)) { mnFile.add(action); } // clear recent mnFile.addSeparator(); mnFile.add(new AppFrameAction("Clear recent files", "Clear recent files", null, null, false, null, this) { @Override public void actionPerformed(ActionEvent e) { PreferencesManager.getSingleton().clearRecentFiles(); } }); // finally exit mnFile.addSeparator(); JMenuItem item = mnFile.add(new AppFrameAction("Exit", "Exit", null, null, false, KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.Event.CTRL_MASK), this) { @Override public void actionPerformed(ActionEvent e) { dispose(); System.exit(0); } }); // item.setAccelerator(((AppFrameAction) item.getAction()).accelerator); mnFile.validate(); }
From source file:ca.phon.app.project.ProjectWindow.java
@Override public void setJMenuBar(JMenuBar menu) { super.setJMenuBar(menu); JMenu projectMenu = new JMenu("Project"); int projectMenuIndex = -1; // get the edit menu and add view commands for (int i = 0; i < menu.getMenuCount(); i++) { JMenu currentBar = menu.getMenu(i); if (currentBar != null && currentBar.getText() != null && currentBar.getText().equals("Workspace")) { projectMenuIndex = i + 1;//from w w w . j a v a 2 s. c o m } } if (projectMenuIndex > 0) { menu.add(projectMenu, projectMenuIndex); } // refresh lists final RefreshAction refreshItem = new RefreshAction(this); projectMenu.add(refreshItem); projectMenu.addSeparator(); // create corpus item final NewCorpusAction newCorpusItem = new NewCorpusAction(this); projectMenu.add(newCorpusItem); // create corpus item final NewSessionAction newSessionItem = new NewSessionAction(this); projectMenu.add(newSessionItem); projectMenu.addSeparator(); final AnonymizeAction anonymizeParticipantInfoItem = new AnonymizeAction(this); projectMenu.add(anonymizeParticipantInfoItem); final CheckTranscriptionsAction repairItem = new CheckTranscriptionsAction(this); projectMenu.add(repairItem); // merge/split sessions final DeriveSessionAction deriveItem = new DeriveSessionAction(this); projectMenu.add(deriveItem); final JMenu teamMenu = new JMenu("Team"); teamMenu.addMenuListener(new MenuListener() { @Override public void menuSelected(MenuEvent e) { teamMenu.removeAll(); if (getProject() != null) { final ProjectGitController gitController = new ProjectGitController(getProject()); if (gitController.hasGitFolder()) { teamMenu.add(new CommitAction(ProjectWindow.this)); teamMenu.addSeparator(); teamMenu.add(new PullAction(ProjectWindow.this)); teamMenu.add(new PushAction(ProjectWindow.this)); } else { final InitAction initRepoAct = new InitAction(ProjectWindow.this); teamMenu.add(initRepoAct); } } } @Override public void menuDeselected(MenuEvent e) { } @Override public void menuCanceled(MenuEvent e) { } }); projectMenu.addSeparator(); projectMenu.add(teamMenu); }