Java Utililty Methods JMenuItem

List of utility methods to do JMenuItem

Description

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

Method

voidsyncMenuItem(final JMenuItem source, final JMenuItem dest)
Brings the destination menu item into sync with the source item.
final boolean enabled = source.isEnabled();
if (dest.isEnabled() != enabled)
    dest.setEnabled(enabled);
final int mnemonic = source.getMnemonic();
if (dest.getMnemonic() != mnemonic)
    dest.setMnemonic(mnemonic);
final String text = source.getText();
if (dest.getText() != text)
...
booleanupdateFilesOpenedMenuItems(File fx, LinkedHashMap filesOpened, ActionListener actionListener)
To use to update JMenuItens for recently opened files
if (filesOpened.containsValue(fx)) {
    for (JMenuItem key : filesOpened.keySet()) {
        if (filesOpened.get(key).equals(fx)) {
            filesOpened.remove(key);
            break;
if (!filesOpened.containsValue(fx)) {
    JMenuItem nMenuItem = new JMenuItem() {
        private static final long serialVersionUID = 1L;
        public String getText() {
            return super.getText();
    };
    nMenuItem.setText(fx.getName());
    nMenuItem.setToolTipText(fx.getAbsolutePath());
    if (actionListener != null)
        nMenuItem.addActionListener(actionListener);
    LinkedHashMap<JMenuItem, File> oldList = new LinkedHashMap<JMenuItem, File>();
    oldList.putAll(filesOpened);
    filesOpened.clear();
    filesOpened.put(nMenuItem, fx);
    filesOpened.putAll(oldList);
} else {
while (filesOpened.size() > 10) {
    Object[] keys = filesOpened.keySet().toArray();
    filesOpened.remove(keys[filesOpened.size() - 1]);
return true;
booleanuseCheckAndArrow(JMenuItem menuItem)
use Check And Arrow
boolean b = true;
if ((menuItem instanceof JMenu) && (((JMenu) menuItem).isTopLevelMenu())) {
    b = false;
return b;
booleanuseCheckAndArrow(JMenuItem menuItem)
Returns false if the component is a JMenu and it is a top level menu (on the menubar).
boolean b = true;
if ((menuItem instanceof JMenu) && (((JMenu) menuItem).isTopLevelMenu())) {
    b = false;
return b;