Java Utililty Methods JMenu

List of utility methods to do JMenu

Description

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

Method

booleanaddSeparatorIfNeeded(JMenu menu)
Convenience method that calls the method addSeparatorIfNeeded(JPopupMenu) with the JPopupMenu of the given menu as parameter.
return addSeparatorIfNeeded(menu.getPopupMenu());
voidapplyDefaultProperties(final JMenu comp)
Sets default background and foreground color as well as a default font for the specified component.
if (comp == null) {
    return;
applyProperties(comp, "Menu.background", 
        "Menu.foreground", 
        "Menu.font"); 
voidassignMnemonics(JMenu menu)
assign Mnemonics
Component[] comps = menu.getMenuComponents();
ArrayList list = new ArrayList();
char mne;
for (int count = 0; count < comps.length; count++) {
    if (comps[count] instanceof JMenuItem) {
        mne = getMnemonic(((JMenuItem) comps[count]).getText(), list);
        ((JMenuItem) comps[count]).setMnemonic(mne);
voidchangeMenuItemsState(final JMenu menu, final boolean enableState)
change Menu Items State
final int size = menu.getItemCount();
for (int i = 0; i < size; i++) {
    final JMenuItem item = menu.getItem(i);
    item.setEnabled(enableState);
voidconstructRecentlyFilesMenuItems(JMenu recentlyOpenFilesMenuItem, LinkedHashMap filesOpenedLHM)
To use to construct JMenuItens for recently opened files.
recentlyOpenFilesMenuItem.removeAll();
if (filesOpenedLHM.size() == 0) {
    recentlyOpenFilesMenuItem.setEnabled(false);
} else {
    recentlyOpenFilesMenuItem.setEnabled(true);
    Iterator<?> it = filesOpenedLHM.keySet().iterator();
    while (it.hasNext()) {
        JMenuItem nMenuItem = (JMenuItem) it.next();
...
booleancontainsMenuComponent(JMenu parent, Component comp)
contains Menu Component
return indexOfMenuComponent(parent, comp) != -1;
intcountCheckBoxMenuItem(JMenu menu)
count Check Box Menu Item
int count = 0;
for (int i = 0; i < menu.getMenuComponentCount(); i++) {
    Component c = menu.getMenuComponent(i);
    if (c instanceof JCheckBoxMenuItem) {
        count++;
return count;
...
voidcreateMenu(String menuText, JMenu menu, ActionListener listener)
create Menu
menu.add(createMenuItem(menuText, listener));
JMenuBarcreateMenuBar(JMenu... menues)
create Menu Bar
JMenuBar menuBar = new JMenuBar();
for (JMenu menu : menues) {
    menuBar.add(menu);
return menuBar;
JMenuItemcreateMenuItem(JMenu parent, String text)
create Menu Item
JMenuItem mi = new JMenuItem();
configureTextAndMnemonic(mi, text);
parent.add(mi);
return mi;