Java Code Examples for javax.swing.JMenu#remove()
The following examples show how to use
javax.swing.JMenu#remove() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OSPFrame.java From osp with GNU General Public License v3.0 | 6 votes |
/** * Removes a menu item with the given name from the menu bar and returns the removed item. * Returns null if menu item does not exist. * * @param menuName String * @return JMenu */ public JMenuItem removeMenuItem(String menuName, String itemName) { JMenu menu = getMenu(menuName); if(menu==null) { return null; } itemName = itemName.trim(); JMenuItem item = null; for(int i = 0; i<menu.getItemCount(); i++) { JMenuItem next = menu.getItem(i); if(next.getText().trim().equals(itemName)) { item = next; menu.remove(i); break; } } return item; }
Example 2
Source File: LogParserView.java From yGuard with MIT License | 5 votes |
static void addRecent( final UiContext context, final File path ) { final JMenu menu = context.recentMenu; final int n = menu.getItemCount(); if (n > 9) { menu.remove(n - 1); } final RecentAction ra = new RecentAction(context, path); final JMenuItem jc = menu.add(ra); ra.setItem(jc); if (n > 0) { menu.remove(menu.getItemCount() - 1); menu.add(jc, 0); } }
Example 3
Source File: LogParserView.java From yGuard with MIT License | 5 votes |
private void updateRecent( final UiContext context, final File path ) { final JMenu menu = context.recentMenu; final JMenuItem ami = getItem(); if (ami != null) { for (int i = 0, n = menu.getItemCount(); i < n; ++i) { final JMenuItem mi = menu.getItem(i); if (mi == ami) { menu.remove(i); menu.add(ami, 0); break; } } } }
Example 4
Source File: WorkspaceSwitchAction.java From netbeans with Apache License 2.0 | 5 votes |
/** Frees all listeners etc from given workspace. */ void detachWorkspace( Workspace workspace, Hashtable workspace2Menu, Hashtable menu2Workspace, Hashtable workspace2Listener, JMenu menu ) { JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem) workspace2Menu.get(workspace); workspace2Menu.remove(workspace); menu2Workspace.remove(workspace2Listener.get(workspace)); workspace2Listener.remove(workspace); menu.remove(menuItem); }
Example 5
Source File: SeparableMenu.java From audiveris with GNU Affero General Public License v3.0 | 5 votes |
/** * Remove any potential orphan separator at the end of the menu. * * @param menu the menu to purge */ public static void trimSeparator (JMenu menu) { int count = menu.getMenuComponentCount(); if ((count > 0) && menu.getMenuComponent(count - 1) instanceof JSeparator) { menu.remove(count - 1); } }
Example 6
Source File: MainFrame.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
/** * Removes duplicated separators from a JMenu * * @param menu the menu */ private static void removeDuplicatedSeparators(JMenu menu) { int separatorCount = 0; for (Component component : menu.getMenuComponents()) { if (component instanceof JPopupMenu.Separator) { separatorCount++; } else { separatorCount = 0; } if (separatorCount > 1) { menu.remove(component); } } }
Example 7
Source File: AbstractMenuCreator.java From wpcleaner with Apache License 2.0 | 5 votes |
/** * Add a submenu to a menu. * If the submenu contains to much elements, it is split into several submenus. * * @param menu Menu. * @param submenu Submenu. * @param begin Number of items kept at the beginning. * @param end Number of items kept at the end. */ public void addSubmenu(JPopupMenu menu, JMenu submenu, int begin, int end) { Configuration config = Configuration.getConfiguration(); final int maxElements = Math.max( config.getInt(null, ConfigurationValueInteger.MENU_SIZE), begin + end + 2); if (submenu.getMenuComponentCount() > maxElements) { List<JMenu> menuList = new ArrayList<JMenu>(); while (submenu.getMenuComponentCount() > begin + end + 1) { int count = Math.min(maxElements, submenu.getMenuComponentCount() - begin - end); JMenu newMenu = new JMenu(submenu.getItem(begin).getText() + "..."); for (int i = 0; i < count; i++) { JMenuItem item = submenu.getItem(begin); submenu.remove(begin); if (item != null) { newMenu.add(item); } else { addSeparator(newMenu); } } menuList.add(newMenu); } for (int i = 0; i < menuList.size(); i++) { submenu.add(menuList.get(i), begin + i); } addSubmenu(menu, submenu, begin, end); } else { menu.add(submenu); } }
Example 8
Source File: MainFrameClassicMenu.java From jpexs-decompiler with GNU General Public License v3.0 | 5 votes |
@Override public void finishMenu(String path) { path = mapping(path); if (path.equals("_") || path.startsWith("_/")) { return; } if (!menuElements.containsKey(path)) { throw new IllegalArgumentException("Invalid menu: " + path); } if (path.startsWith("/file/recent")) { return; } MenuElement me = menuElements.get(path); if (me instanceof JMenu) { JMenu jm = (JMenu) me; if (jm.getMenuComponentCount() == 1) { String parentPath = path.contains("/") ? path.substring(0, path.lastIndexOf('/')) : ""; MenuElement parMe = menuElements.get(parentPath); JMenuItem mi = (JMenuItem) jm.getMenuComponent(0); jm.remove(mi); if (parMe instanceof JMenu) { JMenu parMenu = (JMenu) parMe; parMenu.remove(jm); parMenu.add(mi); } else if (parMe instanceof JMenuBar) { JMenuBar parMenuBar = (JMenuBar) parMe; parMenuBar.remove(jm); parMenuBar.add(mi); } } } }
Example 9
Source File: SeparableMenu.java From libreveris with GNU Lesser General Public License v3.0 | 5 votes |
/** * Remove any potential orphan separator at the end of the menu. * * @param menu the menu to purge */ public static void trimSeparator (JMenu menu) { int count = menu.getMenuComponentCount(); if ((count > 0) && menu.getMenuComponent(count - 1) instanceof JSeparator) { menu.remove(count - 1); } }