JRootPane pane = frame.getRootPane();
JLayeredPane layered = pane.getLayeredPane();
Object[] comps = layered.getComponents();
for (int i = 0; i < comps.length; i++) {
if (comps[i] instanceof MenuBar) {
MenuBar bar = (MenuBar) comps[i];
bar.waitFinished();
int num = bar.getMenuCount();
for (int j = 0; j < num; j++) {
Object o = bar.getMenu(j);
if (o != null) {
JMenu menu = (JMenu) o;
menu.addMenuListener(new MenuListener() {
public void menuSelected(MenuEvent e) {