Java Utililty Methods JMenuBar

List of utility methods to do JMenuBar

Description

The list of methods to do JMenuBar are organized into topic(s).

Method

voidaddFastKeys(JMenuBar menuBar)
add Fast Keys
for (Component menuComponent : menuBar.getComponents()) { 
    JMenu menu = (JMenu) menuComponent;
    menu.setMnemonic(menu.getText().charAt(menu.getText().indexOf('&') + 1));
    menu.setText(menu.getText().replace("&", ""));
    for (Component menuItemComponent : menu.getMenuComponents())
        if (menuItemComponent instanceof JMenuItem) { 
            JMenuItem menuItem = (JMenuItem) menuItemComponent;
            menuItem.setMnemonic(menuItem.getText().charAt(menuItem.getText().indexOf('&') + 1));
...
voidaddMenuItems(JMenuBar menu, JComponent... items)
add Menu Items
for (JComponent item : items) {
    menu.add(item);
voidapplyDefaultProperties(final JMenuBar comp)
Sets default background and foreground color as well as a default font for the specified component.
if (comp == null) {
    return;
applyProperties(comp, "MenuBar.background", 
        "MenuBar.foreground", 
        "MenuBar.font"); 
JMenuBarcloneMenuBar(final JMenuBar menubar)
Creates a copy of this menu bar, whose contents update automatically whenever the original menu bar changes.
if (menubar == null)
    return null;
final JMenuBar jmb = new JMenuBar();
final int count = menubar.getMenuCount();
for (int i = 0; i < count; i++)
    jmb.add(cloneMenuItem(menubar.getMenu(i)));
return jmb;
JMenucreateMenuInMenuBar(final JMenuBar menuBar, final String menuName)
Adds a menu to the specified menu bar.
final JMenu menu = new JMenu();
menu.setText(menuName);
menuBar.add(menu);
return menu;
JMenuItemfindItem(JMenuBar menuBar, String menuName, String menuItemName)
find Item
Component component = findMenuComponent(menuBar, menuName, menuItemName);
return component instanceof JMenuItem ? (JMenuItem) component : null;
JMenufindMenu(JMenuBar bar, Class type)
find Menu
if (bar != null) {
    int count = bar.getMenuCount();
    for (int i = 0; i < count; i++) {
        JMenu menu = bar.getMenu(i);
        if (type.isInstance(menu)) {
            return menu;
return null;
JMenufindMenu(JMenuBar menuBar, String menuName)
find Menu
MenuElement[] menus = menuBar.getSubElements();
for (int ii = 0; ii < menus.length; ++ii) {
    JMenu menu = (JMenu) menus[ii].getComponent();
    if (menu.getText().equals(menuName))
        return menu;
return null;
JMenufindMenu(JMenuBar menuBar, String menuName, String subMenuName)
find Menu
Component component = findMenuComponent(menuBar, menuName, subMenuName);
return component instanceof JMenu ? (JMenu) component : null;
JMenufindMenu(JMenuBar menuBar, String name, boolean deepSearch)
find Menu
int n = menuBar.getMenuCount();
for (int i = 0; i < n; i++) {
    JMenu menu = menuBar.getMenu(i);
    if (name.equals(menu.getName())) {
        return menu;
if (deepSearch) {
...