List of utility methods to do JMenu
JMenuItem | createMenuItemCustomAction(JMenu menu, int type, String text, String command, ImageIcon image, int acceleratorKey, String toolTip, ActionListener action) create Menu Item Custom Action JMenuItem item; switch (type) { case RADIO: item = new JRadioButtonMenuItem(); break; case CHECK: item = new JCheckBoxMenuItem(); break; ... |
void | createMenuItems(JMenu menu, String[] menuItemNames) create Menu Items ArrayList menuItems = new ArrayList(); JMenuItem menuItem = null; for (int i = 0; i < menuItemNames.length; i++) { menuItem = new JMenuItem(menuItemNames[i]); menuItem.setMnemonic(menuItemNames[i].charAt(0)); menu.add(menuItem); |
JMenu | createTooltiplessJMenu(Action action) create Tooltipless J Menu JMenu result = new JMenu(action) { @Override public JMenuItem add(Action a) { JMenuItem result = super.add(a); result.setToolTipText(null); return result; }; ... |
void | disableMenuIfAllMenuItemsAreDisabled(JMenu menu, boolean bRemoveEmptySubMenus) disables (recursively) the given menu if all menu items in the menu (all direct children) are disabled. int iEnabledMenuItems = 0; for (Component comp : menu.getMenuComponents()) { if (comp instanceof JMenuItem) { final JMenuItem mi = (JMenuItem) comp; if (mi instanceof JMenu) { final JMenu menuChild = (JMenu) mi; disableMenuIfAllMenuItemsAreDisabled(menuChild, bRemoveEmptySubMenus); if (bRemoveEmptySubMenus && !mi.isEnabled()) { ... |
void | enableAll(JMenu menu) Convenience method that recursively enables every JMenu and JMenuItem inside "menu". for (int i = 0; i < menu.getMenuComponentCount(); i++) { Component obj = menu.getMenuComponent(i); if (obj instanceof JMenuItem) { ((JMenuItem) obj).setEnabled(true); } else if (obj instanceof JMenu) { enableAll((JMenu) obj); |
void | fillFontMenu(JMenu fontMenu) fill Font Menu GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); Font[] fonts = ge.getAllFonts(); List<String> names = new ArrayList<>(); for (Font f : fonts) { String name = f.getFamily(); if (!names.contains(name)) { addMenuItem(null, fontMenu, name); names.add(name); ... |
T | findMenuComponent(JMenu menu, String menuComponentName, Class find Menu Component for (int i = 0; i < menu.getMenuComponentCount(); i++) { Component component = menu.getMenuComponent(i); if (menuComponentName.equals(component.getName()) && componentClass.isInstance(component)) return componentClass.cast(component); return null; |
JMenuItem | findMenuItem(JMenu menu, String menuItemName) find Menu Item if (menu.getItemCount() > 0) { for (int ii = 0; ii < menu.getItemCount(); ++ii) { JMenuItem menuItem = menu.getItem(ii); if (menuItem.getText().equals(menuItemName)) return menuItem; return null; ... |
JMenuItem | findMenuItemByActionCommand(JMenu menu, String sActionCommand) find Menu Item By Action Command for (Component comp : menu.getMenuComponents()) { if (comp instanceof JMenuItem) { final JMenuItem mi = (JMenuItem) comp; if (sActionCommand.equals(mi.getActionCommand())) { return mi; return null; |
JMenu | findSubMenuWithLabel(JMenu menu, String text) find Sub Menu With Label for (Component submenu : menu.getMenuComponents()) { if (submenu instanceof JMenu && text.equals(((JMenu) submenu).getText())) { return (JMenu) submenu; return null; |