Example usage for javax.swing JPanel getInputMap

List of usage examples for javax.swing JPanel getInputMap

Introduction

In this page you can find the example usage for javax.swing JPanel getInputMap.

Prototype

public final InputMap getInputMap() 

Source Link

Document

Returns the InputMap that is used when the component has focus.

Usage

From source file:Main.java

public Main() {
    int MASK = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();

    KeyStroke exitKey = KeyStroke.getKeyStroke(KeyEvent.VK_W, MASK);
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);

    JMenu fileMenu = new JMenu("File");
    JMenuItem fileExit = new JMenuItem(exitAction);
    fileMenu.add(fileExit);//from w ww.ja va  2  s. c  om
    JMenuBar menu = new JMenuBar();
    menu.add(fileMenu);

    JDialog d = new JDialog(this, "Dialog");
    JPanel p = new JPanel();
    p.getInputMap().put(exitKey, exitName);
    p.getActionMap().put(exitName, exitAction);
    p.add(new JButton(exitAction));
    d.add(p);
    d.pack();
    d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

    this.setJMenuBar(menu);
    this.pack();
    this.setSize(new Dimension(320, 240));
    this.setVisible(true);
    d.setLocation(this.getRootPane().getContentPane().getLocationOnScreen());
    d.setVisible(true);
}

From source file:org.pentaho.reporting.engine.classic.core.modules.gui.base.PreviewParametersDialog.java

private void initialize(final MasterReport report) {
    if (report == null) {
        throw new NullPointerException();
    }/*  w  w  w.ja v a  2 s  .  co m*/

    masterReport = report;
    messages = new ResourceBundleSupport(Locale.getDefault(), SwingPreviewModule.BUNDLE_NAME,
            ObjectUtilities.getClassLoader(PreviewParametersDialog.class));
    confirmAction = new OkAction();

    setTitle(messages.getString("PreviewParametersDialog.Title"));
    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

    final JPanel contentPane = new JPanel();
    contentPane.setLayout(new BorderLayout());
    contentPane.add(createParametersPanel(), BorderLayout.CENTER);
    contentPane.add(createButtonsPanel(), BorderLayout.SOUTH);
    setContentPane(contentPane);

    final InputMap inputMap = contentPane.getInputMap();
    final ActionMap actionMap = contentPane.getActionMap();

    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "confirm"); // NON-NLS
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel"); // NON-NLS
    actionMap.put("confirm", new OkAction()); // NON-NLS
    actionMap.put("cancel", new CancelAction()); // NON-NLS

    setModal(true);
    pack();
    LibSwingUtil.centerDialogInParent(this);
}