List of usage examples for javax.swing JMenu addActionListener
public void addActionListener(ActionListener l)
ActionListener
to the button. From source file:TreeUtil.java
/** * Makes menus from the root node/*from w w w.j a v a2 s . c o m*/ */ public JMenuItem getMenus() { JMenu rootMenu = new JMenu(itsRootNode.getUserObject().toString()); rootMenu.setActionCommand("TreeMenu"); rootMenu.addActionListener(this); return getMenus(itsRootNode, rootMenu); }
From source file:org.openmicroscopy.shoola.env.ui.TaskBarView.java
/** * Copies the items from the specified menu and creates a new menu. * * @param original The menu to handle./* www.j a v a2s . c om*/ * @return See above. */ private JMenu copyItemsFromMenu(JMenu original) { Component[] comps = original.getPopupMenu().getComponents(); JMenu menu = new JMenu(); menu.setText(original.getText()); menu.setToolTipText(original.getToolTipText()); ActionListener[] al = original.getActionListeners(); for (int j = 0; j < al.length; j++) menu.addActionListener(al[j]); MenuKeyListener[] mkl = original.getMenuKeyListeners(); for (int j = 0; j < mkl.length; j++) menu.addMenuKeyListener(mkl[j]); MenuListener[] ml = original.getMenuListeners(); for (int j = 0; j < ml.length; j++) menu.addMenuListener(ml[j]); for (int i = 0; i < comps.length; i++) { if (comps[i] instanceof JMenu) { menu.add(copyItemsFromMenu((JMenu) comps[i])); } else if (comps[i] instanceof JMenuItem) { menu.add(copyItem((JMenuItem) comps[i])); } else if (comps[i] instanceof JSeparator) { menu.add(new JSeparator(JSeparator.HORIZONTAL)); } } return menu; }