Java Code Examples for javax.swing.JMenu#getMenuComponentCount()
The following examples show how to use
javax.swing.JMenu#getMenuComponentCount() .
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: BindAction.java From netbeans with Apache License 2.0 | 6 votes |
private void createBindingsSubmenu(JMenu menu) { if (menu.getMenuComponentCount() > 0) menu.removeAll(); Node[] nodes = getActivatedNodes(); if (nodes.length != 1) return; RADComponentCookie radCookie = nodes[0].getCookie(RADComponentCookie.class); if (radCookie == null) return; BindingProperty[][] bindingProps = radCookie.getRADComponent().getBindingProperties(); BindingProperty[] props = bindingProps[(bindingProps[0].length==0) ? 1 : 0]; if (props.length > 0) { for (BindingProperty prop : props) { BindingMenuItem mi = new BindingMenuItem(prop); mi.addActionListener(mi); menu.add(mi); } } else { JMenuItem item = new JMenuItem(NbBundle.getMessage(BindAction.class, "MSG_NoBinding")); // NOI18N item.setEnabled(false); menu.add(item); } }
Example 2
Source File: MenuComboBox.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Creates the sub menu. * * @param localMenu the local menu * @param group the group */ private void createSubMenu(ComboMenu localMenu, ValueComboBoxDataGroup group) { JMenu subMenu = new JMenu(group.getGroupName()); for (ValueComboBoxData data : group.getDataList()) { if (VendorOptionManager.getInstance() .isAllowed(vendorOptionVersionsList, data.getVendorOption())) { ComboMenuItem menuItem = new ComboMenuItem(data); subMenu.add(menuItem); dataMap.put(data.getKey(), data); if (firstValue == null) { firstValue = data; } } } if (subMenu.getMenuComponentCount() > 1) { localMenu.add(subMenu); } }
Example 3
Source File: LoadMacroMenu.java From tn5250j with GNU General Public License v2.0 | 6 votes |
/** * Create the scripts menu(s) from the vector of macros provided * * @param menu * @param vector * @param start */ private static void createScriptsMenu(JMenu menu, Vector vector, int start) { JPopupMenu jpop = new JPopupMenu(); jpop.add("Delete"); for (int i = start; i < vector.size(); i++) { Object obj = vector.elementAt(i); if (obj instanceof ExecuteScriptAction) { menu.add((ExecuteScriptAction)obj); } else if (obj instanceof Vector) { Vector subvector = (Vector)obj; String name = (String)subvector.elementAt(0); JMenu submenu = new JMenu(name); createScriptsMenu(submenu,subvector,1); if(submenu.getMenuComponentCount() == 0) { submenu.add(LangTool.getString("popup.noScripts")); } menu.add(submenu); } } }
Example 4
Source File: OurUtil.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Convenience method that recursively enables every JMenu and JMenuItem inside * "menu". * * @param menu - the menu to start the recursive search */ public static void enableAll(JMenu menu) { for (int i = 0; i < menu.getMenuComponentCount(); i++) { Component x = menu.getMenuComponent(i); if (x instanceof JMenuItem) ((JMenuItem) x).setEnabled(true); else if (x instanceof JMenu) enableAll((JMenu) x); } }
Example 5
Source File: ResourceLoader.java From ramus with GNU General Public License v3.0 | 5 votes |
public static void setMenuText(final JMenu menu) { menu.setText(getString(menu.getText())); for (int i = 0; i < menu.getMenuComponentCount(); i++) { if (isParent(JMenuItem.class, menu.getMenuComponent(i).getClass()) && !isParent(JMenu.class, menu.getMenuComponent(i) .getClass())) setMenuItemText((JMenuItem) menu.getMenuComponent(i)); else if (menu.getMenuComponent(i).getClass() == JMenu.class) setMenuText((JMenu) menu.getMenuComponent(i)); } }
Example 6
Source File: MnemonicFactory.java From ramus with GNU General Public License v3.0 | 5 votes |
private static void setMnemonics(final JMenuItem item) { if (item instanceof JMenu) { final JMenu menu = (JMenu) item; final int c = menu.getMenuComponentCount(); final ArrayList<JMenuItem> list = new ArrayList<JMenuItem>(c); for (int i = 0; i < c; i++) { final Component co = menu.getMenuComponent(i); if (co instanceof JMenuItem) list.add((JMenuItem) co); } if (list.size() > 0) setMnemonics(list); } }
Example 7
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 8
Source File: MenuScroller.java From megamek with GNU General Public License v2.0 | 5 votes |
/** * Take any given memu object and turn on scrollbars if it contains more than 20 items. * Then, cycle through all submenus recursively. * * @param menu */ public static void createScrollBarsOnMenus(JMenu menu) { if (menu.getMenuComponentCount() > 20) { MenuScroller.setScrollerFor(menu, 20); } for (int i = 0; i < menu.getMenuComponentCount(); i++) { if (menu.getMenuComponent(i) instanceof JMenu) { MenuScroller.createScrollBarsOnMenus(((JMenu)menu.getMenuComponent(i))); } } }
Example 9
Source File: AbstractMenuCreator.java From wpcleaner with Apache License 2.0 | 5 votes |
/** * Add a separator to a menu if useful. * * @param menu Menu. * @return Number of items added. */ public int addSeparator(JMenu menu) { if ((menu == null) || (menu.getMenuComponentCount() == 0)) { return 0; } Component item = menu.getMenuComponent(menu.getMenuComponentCount() - 1); if (!(item instanceof JMenuItem)) { return 0; } menu.add(new JSeparator()); return 1; }
Example 10
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 11
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 12
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); } }
Example 13
Source File: FontSizer.java From osp with GNU General Public License v3.0 | 5 votes |
/** * Sets the menu font. * * @param m a menu * @param font the font */ private static void setMenuFont(JMenu m, Font font) { m.setFont(font); for(int i = 0; i<m.getMenuComponentCount(); i++) { m.getMenuComponent(i).setFont(font); if(m.getMenuComponent(i) instanceof JMenu) { setMenuFont((JMenu) m.getMenuComponent(i), font); } } }