Here you can find the source of createMenuItem(Action a)
Parameter | Description |
---|---|
a | The action for which to create the menu item. |
public static JMenuItem createMenuItem(Action a)
//package com.java2s; /*/* ww w . j a va2 s . c o m*/ * Copyright (C) 2001-2013 Michael Koch (tensberg@gmx.net) * * This file is part of JGloss. * * JGloss is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * JGloss is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with JGloss; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * */ import javax.swing.Action; import javax.swing.JMenuItem; import javax.swing.KeyStroke; public class Main { /** * Creates a JMenuItem from an action. All properties from the action, including the * accelerator key, will be taken from the action. CAUTION: the created menu item adds a * <CODE>propertyChangeListener</CODE> to the action. Thus the item can't be garbage collected * while the action object is still alive. If the menu item is no longer used, the action must be * removed through a call of <CODE>item.setAction( null)</CODE>. * * @param a The action for which to create the menu item. * @return The newly created menu item. */ public static JMenuItem createMenuItem(Action a) { JMenuItem item = new JMenuItem(); item.setAction(a); KeyStroke stroke = (KeyStroke) a.getValue(Action.ACCELERATOR_KEY); if (stroke != null) { item.setAccelerator(stroke); } return item; } }