Java Swing Menu Item createMenuItem(String strTitle, String strActionCommand, ActionListener alListener)

Here you can find the source of createMenuItem(String strTitle, String strActionCommand, ActionListener alListener)

Description

Create a popup menu item

License

Open Source License

Parameter

Parameter Description
strTitle - title
strActionCommand - action command
alListener - action listener

Return

JMenuItem

Declaration

public static JMenuItem createMenuItem(String strTitle, String strActionCommand, ActionListener alListener) 

Method Source Code

//package com.java2s;

import java.awt.event.ActionListener;

import javax.swing.JMenuItem;

public class Main {

    public static JMenuItem createMenuItem(String strTitle, String strActionCommand, ActionListener alListener) {
        JMenuItem deleteItem = new JMenuItem();
        //set title
        if (strTitle != null && !strTitle.isEmpty()) {
            deleteItem.setText(strTitle);
        }/*from w w w.j  av a  2  s.c om*/
        //set action command
        if (strActionCommand != null && !strActionCommand.isEmpty()) {
            deleteItem.setActionCommand(strActionCommand);
        }
        //set action listener
        if (alListener != null) {
            deleteItem.addActionListener(alListener);
        }
        return deleteItem;
    }
}

Related

  1. createMenuItem(String caption, Action action)
  2. createMenuItem(String menuItemName, ActionListener actionListener)
  3. createMenuItem(String menuText, ActionListener listener)
  4. createMenuitem(String name, ActionListener listener)
  5. createMenuItem(String name, String description, int mnemonic, int accelerator, ActionListener listener)
  6. createMenuItem(String text, boolean visible)
  7. createMenuItem(String text, Icon icon, String toolTip, ActionListener... listeners)
  8. createMenuItem(T source, int mnemonic, String description, E action)
  9. createRadioButtonMenuItem(final String text, final boolean selected)