Java Code Examples for javax.swing.JMenu#getItem()
The following examples show how to use
javax.swing.JMenu#getItem() .
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: AbstractMenuFactory.java From netbeans with Apache License 2.0 | 6 votes |
private void updateMenu (JMenu menu) { ActionProvider provider = getEngine().getActionProvider(); Map context = getEngine().getContextProvider().getContext(); String containerCtx = (String) menu.getClientProperty(KEY_CONTAINERCONTEXT); boolean isDynamic = getEngine().getContainerProvider().isDynamicContext( ContainerProvider.TYPE_MENU, containerCtx); String[] actions = provider.getActionNames(containerCtx); // System.err.println("Updating menu " + containerCtx + "actions: " + Arrays.asList(actions)); int count = menu.getItemCount(); // System.err.println("Item count = " + count); //XXX for dynamic menus, we'll need to compare the contents of the //menu with the list of strings, and add/prune for (int i=0; i < count; i++) { JMenuItem item = menu.getItem(i); if (item != null) { String action = (String) item.getClientProperty (KEY_ACTION); configureMenuItem (item, containerCtx, action, provider, context); } } }
Example 2
Source File: ViewHelper.java From FastCopy with Apache License 2.0 | 6 votes |
/** * Resgier allthe components in the jFrame. * * @param c * @return */ public static List<Component> getAllComponents(final Container c) { Component[] comps = c.getComponents(); List<Component> compList = new ArrayList<Component>(); for (Component comp : comps) { compList.add(comp); if (comp instanceof JMenu) { JMenu menu = (JMenu) comp; for (int i = 0; i < menu.getItemCount(); i++) { if (menu.getItem(i)!=null) compList.add(menu.getItem(i)); } } else if (comp instanceof Container) compList.addAll(getAllComponents((Container) comp)); } return compList; }
Example 3
Source File: MainMenu.java From nmonvisualizer with Apache License 2.0 | 6 votes |
@Override public void currentIntervalChanged(Interval interval) { JMenu intervals = getMenu(2); for (int i = 0; i < intervals.getItemCount(); i++) { JMenuItem item = intervals.getItem(i); if ((item != null) && (item.getClass() == IntervalMenuItem.class)) { IntervalMenuItem intervalItem = (IntervalMenuItem) item; if (intervalItem.getInterval().equals(interval)) { intervalItem.setSelected(true); break; } } } }
Example 4
Source File: MainMenu.java From nmonvisualizer with Apache License 2.0 | 6 votes |
public void intervalRenamed(Interval interval) { JMenu intervals = getMenu(2); for (int i = 0; i < intervals.getItemCount(); i++) { JMenuItem item = intervals.getItem(i); if ((item != null) && (item.getClass() == IntervalMenuItem.class)) { IntervalMenuItem intervalItem = (IntervalMenuItem) item; if (intervalItem.getInterval().equals(interval)) { intervalItem.setText(TimeFormatCache.formatInterval(interval)); break; } } } }
Example 5
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 6
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 7
Source File: DynamicMenu.java From netbeans with Apache License 2.0 | 5 votes |
protected static void enableMenu (JMenu menu) { boolean enabled = false; for (int i = 0; i < menu.getItemCount(); ++i) { JMenuItem item = menu.getItem(i); if (item != null && item.isEnabled()) { enabled = true; break; } } menu.setEnabled(enabled); }
Example 8
Source File: DynamicMenu.java From netbeans with Apache License 2.0 | 5 votes |
protected static void enableMenu (JMenu menu) { boolean enabled = false; for (int i = 0; i < menu.getItemCount(); ++i) { JMenuItem item = menu.getItem(i); if (item != null && item.isEnabled()) { enabled = true; break; } } menu.setEnabled(enabled); }
Example 9
Source File: ShelveChangesMenu.java From netbeans with Apache License 2.0 | 5 votes |
private void enableMenu (JMenu menu) { boolean enabled = false; for (int i = 0; i < menu.getItemCount(); ++i) { JMenuItem item = menu.getItem(i); if (item != null && item.isEnabled()) { enabled = true; break; } } menu.setEnabled(enabled); }
Example 10
Source File: DynamicMenu.java From netbeans with Apache License 2.0 | 5 votes |
protected static void enableMenu (JMenu menu) { boolean enabled = false; for (int i = 0; i < menu.getItemCount(); ++i) { JMenuItem item = menu.getItem(i); if (item != null && item.isEnabled()) { enabled = true; break; } } menu.setEnabled(enabled); }
Example 11
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 12
Source File: ComboMenuBar.java From ChatGameFontificator with The Unlicense | 5 votes |
private void applyFilter(String filterText) { resetMenu(); for (JMenu menuFolder : allMenuFolders.keySet()) { boolean atLeastOneHit = false; boolean matchesMenu = menuFolder.getText().toLowerCase().contains(filterText.toLowerCase().trim()); for (int i = 0; i < menuFolder.getItemCount(); i++) { GameFontMenuItem gfmi = (GameFontMenuItem) menuFolder.getItem(i); final boolean matchesGame = gfmi.isMatchingFilterGame(filterText); final boolean matchesGenre = gfmi.isMatchingFilterGenre(filterText); final boolean matchesSystem = gfmi.isMatchingFilterSystem(filterText); boolean hit = matchesMenu || matchesGame || matchesGenre || matchesSystem; gfmi.setVisible(hit); if (hit) { atLeastOneHit = true; } } allMenuItems.get(menuFolder).setFiltered(!atLeastOneHit); } setMenuItemFilterVisibility(); }
Example 13
Source File: Utils.java From j-j-jvm with Apache License 2.0 | 5 votes |
public static final void changeMenuItemsState(final JMenu menu, final boolean enableState) { final int size = menu.getItemCount(); for (int i = 0; i < size; i++) { final JMenuItem item = menu.getItem(i); item.setEnabled(enableState); } }