List of usage examples for javax.swing JMenuBar getComponentCount
public int getComponentCount()
From source file:com.net2plan.gui.GUINet2Plan.java
private static JMenuItem getCurrentMenu(JMenuBar menubar, JMenu parent, String itemName) { int pos = itemName.indexOf('|'); if (pos == -1) { if (parent == null) throw new RuntimeException("Bad"); JMenuItem menuItem = new JMenuItem(itemName); parent.add(menuItem);/* ww w. j a va2s.c o m*/ return menuItem; } else { String parentName = itemName.substring(0, pos); JMenu new_parent = null; MenuElement[] children; if (menubar != null) children = menubar.getSubElements(); else if (parent != null) children = parent.getSubElements(); else throw new RuntimeException("Bad"); for (MenuElement item : children) { if (!(item instanceof JMenu) || !((JMenu) item).getText().equalsIgnoreCase(parentName)) continue; new_parent = (JMenu) item; break; } if (new_parent == null) { new_parent = new JMenu(parentName); if (menubar != null) { if (parentName.equals("Tools")) { menubar.add(new_parent, 1); new_parent.setMnemonic('T'); } else { menubar.add(new_parent, menubar.getComponentCount() - 1); } } else if (parent != null) { parent.add(new_parent); } else { throw new RuntimeException("Bad"); } } String new_itemName = itemName.substring(pos + 1); return getCurrentMenu(null, new_parent, new_itemName); } }