Java Swing Menu createMenu(String label, int mnemonic, String description)

Here you can find the source of createMenu(String label, int mnemonic, String description)

Description

create Menu

License

Open Source License

Declaration

public static JMenu createMenu(String label, int mnemonic, String description) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.event.ActionListener;
import java.awt.event.ItemListener;
import java.util.EventListener;
import javax.swing.Action;

import javax.swing.JMenu;
import javax.swing.JMenuItem;

public class Main {
    public static JMenu createMenu(String label, int mnemonic, String description) {
        return createMenuItem(new JMenu(label), mnemonic, description, null);
    }/* ww w . j a v  a2s  .co  m*/

    public static <T extends Action> JMenuItem createMenu(Class<T> actionClass) {
        try {
            return new JMenuItem(actionClass.newInstance());
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static JMenuItem createMenuItem(String label, int mnemonic, String description, ActionListener action) {
        return createMenuItem(new JMenuItem(label), mnemonic, description, action);
    }

    public static <T extends JMenuItem, E extends EventListener> T createMenuItem(T source, int mnemonic,
            String description, E action) {
        source.setMnemonic(mnemonic);
        source.getAccessibleContext().setAccessibleDescription(description);

        if (action instanceof ActionListener) {
            source.addActionListener((ActionListener) action);
        } else if (action instanceof ItemListener) {
            source.addItemListener((ItemListener) action);
        }

        return source;
    }
}

Related

  1. createActionMenu(JTextComponent text, boolean includeModifying)
  2. createMenu(final String label, final String mnemonic, final String accessibleDescription)
  3. createMenu(final String name, final int mnemonic)
  4. createMenu(final String text)
  5. createMenu(final String text, final char mnemonic)
  6. createMenu(String label, Object... objects)
  7. createMenu(String name, Object[] item, int[] accelerator, ActionListener listener)
  8. createMenu(String text)
  9. createMenuKeyMask(final int aKeyStroke, final int... aMasks)