Java JDialog setActionsMenu(JDialog dialog, MenuElement menu)

Here you can find the source of setActionsMenu(JDialog dialog, MenuElement menu)

Description

set Actions Menu

License

Open Source License

Declaration

private static void setActionsMenu(JDialog dialog, MenuElement menu) 

Method Source Code

//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);
            }
        }
    }
}

Related

  1. positionDialogInContainer(JDialog dialog, Container frame, int horizontal, int vertical)
  2. renderDialog(JDialog thedialog, String szMessage, int noffsetx, int noffsety)
  3. resizeDialogToScreen(JDialog dialog)
  4. rptaConfirmDialog(JDialog pJDialog, String pMensaje)
  5. runProgressBar(final Runnable runnable, final JDialog dialog)
  6. setCursorFree(JDialog dialog)
  7. setDirty(JDialog dialog, boolean isDirty)
  8. setHelpDialogLoc(JButton odsHelpButton, JDialog helpDialog)
  9. setSize(JDialog dialog, int width, int height)