Here you can find the source of setActionsMenu(JDialog dialog, MenuElement menu)
private static void setActionsMenu(JDialog dialog, MenuElement menu)
//package com.java2s; //License from project: Open Source License import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JMenuItem; import javax.swing.MenuElement; public class Main { private static int counter = 0; private static void setActionsMenu(JDialog dialog, MenuElement menu) { MenuElement[] subItems = menu.getSubElements(); for (int i = 0; i < subItems.length; i++) { MenuElement c = subItems[i]; if (c instanceof JMenuItem) { final JMenuItem menuItem = (JMenuItem) c; if (menuItem.getAccelerator() != null) { String key = "hackAction" + counter++; dialog.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put(menuItem.getAccelerator(), key); if (menuItem.getAction() == null) { dialog.getRootPane().getActionMap().put(key, new AbstractAction() { public void actionPerformed(ActionEvent e) { menuItem.doClick(); }// www .j a v a 2 s. c o m }); } else { dialog.getRootPane().getActionMap().put(key, menuItem.getAction()); } // System.out.println(key + " : " // + menuItem.getActionCommand() + " : " // + menuItem.getAccelerator() + " : " // + menuItem.getAction()); } } else if (c.getSubElements().length > 0) { setActionsMenu(dialog, c); } } } }