Java Code Examples for javax.swing.JMenu#getMenuComponent()

The following examples show how to use javax.swing.JMenu#getMenuComponent() . 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: OurUtil.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * 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 2
Source File: MnemonicFactory.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
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 3
Source File: SeparableMenu.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 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 4
Source File: MenuScroller.java    From megamek with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 5
Source File: AbstractMenuCreator.java    From wpcleaner with Apache License 2.0 5 votes vote down vote up
/**
 * 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 6
Source File: MainFrameClassicMenu.java    From jpexs-decompiler with GNU General Public License v3.0 5 votes vote down vote up
@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 7
Source File: SeparableMenu.java    From libreveris with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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: FontSizer.java    From osp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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);
    }
  }
}