List of usage examples for javax.swing JMenuItem getActionCommand
public String getActionCommand()
From source file:Main.java
/** * Creates a copy of this menu item, whose contents update automatically * whenever the original menu item changes. */// w ww. j ava 2s . com public static JMenuItem cloneMenuItem(final JMenuItem item) { if (item == null) return null; JMenuItem jmi; if (item instanceof JMenu) { final JMenu menu = (JMenu) item; final JMenu jm = new JMenu(); final int count = menu.getItemCount(); for (int i = 0; i < count; i++) { final JMenuItem ijmi = cloneMenuItem(menu.getItem(i)); if (ijmi == null) jm.addSeparator(); else jm.add(ijmi); } jmi = jm; } else jmi = new JMenuItem(); final ActionListener[] l = item.getActionListeners(); for (int i = 0; i < l.length; i++) jmi.addActionListener(l[i]); jmi.setActionCommand(item.getActionCommand()); syncMenuItem(item, jmi); linkMenuItem(item, jmi); return jmi; }
From source file:com.digitalgeneralists.assurance.ui.MainWindow.java
private void setMenuState(int menuIndex, Boolean enabled, Boolean ignoreExceptions) { JMenu relevantMenu = this.menuBar.getMenu(menuIndex); if (relevantMenu != null) { for (int i = 0; i < relevantMenu.getItemCount(); i++) { JMenuItem item = relevantMenu.getItem(i); // NOTE: I don't like how Swing manages menus. if (item != null) { if (ignoreExceptions || (!AssuranceActions.newScanDefinitonAction.equals(item.getActionCommand()))) { item.setEnabled(enabled); }/*from w w w . jav a 2s .c o m*/ } } } }