Java JFrame registerMenuShortcut(String uniqueActionName, Action action, int keyCode, JFrame frame)

Here you can find the source of registerMenuShortcut(String uniqueActionName, Action action, int keyCode, JFrame frame)

Description

Adds a menu shortcut (or accelerator) to the input map.

License

Open Source License

Declaration

public static void registerMenuShortcut(String uniqueActionName, Action action, int keyCode, JFrame frame) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import javax.swing.*;

public class Main {
    /**//  ww  w  .  jav a 2 s .co  m
     * Adds a menu shortcut (or accelerator) to the input map. This can be used
     * to add multiple shortcuts to a menu item.
     * @uniqueActionName A unique name.
     * @action The action to add.
     * @keyCode Virtual key code, e.g. KeyEvent.VK_L
     * @frame The frome for which to add the action.
     */
    public static void registerMenuShortcut(String uniqueActionName, Action action, int keyCode, JFrame frame) {

        JRootPane rootPane = frame.getRootPane();
        InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
        ActionMap actionMap = rootPane.getActionMap();
        int ctrlKey = java.awt.Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
        inputMap.put(KeyStroke.getKeyStroke(keyCode, ctrlKey), uniqueActionName);
        actionMap.put(uniqueActionName, action);

    }
}

Related

  1. popupError(JFrame parent, String title, String text)
  2. position(JFrame f)
  3. putOnWidestScreen(JFrame frame)
  4. refreshShape(final JFrame frame)
  5. registerCloseAction(final JFrame dialog, KeyStroke keyStroke)
  6. renderDialog(JFrame theframe, String szMessage, int noffsetx, int noffsety)
  7. replaceGlassPane(JFrame frame, Component newGlassPane)
  8. restoreFrame(Class pClass, final JFrame pFrame, String pFrameId)
  9. restoreFrame(JFrame frame)