Java JDialog Key Event installEnterKey(final JDialog comp, final Action action)

Here you can find the source of installEnterKey(final JDialog comp, final Action action)

Description

install Enter Key

License

Open Source License

Declaration

public static void installEnterKey(final JDialog comp, final Action action) 

Method Source Code

//package com.java2s;
/*//  w  w  w.j a v a2s.  c o  m
 * Copyright (C) 2005 G?rard Milmeister
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of version 2 of the GNU General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 */

import java.awt.event.KeyEvent;
import javax.swing.*;

public class Main {
    public static void installEnterKey(final JDialog comp, final Action action) {
        KeyStroke enterKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false);
        comp.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(enterKeyStroke, "ENTER"); //$NON-NLS-1$
        comp.getRootPane().getActionMap().put("ENTER", action); //$NON-NLS-1$
    }
}

Related

  1. installCloseKeyBinding(final JDialog dialog)
  2. loadCommonKeyMap(final JDialog dialog)
  3. registerCloseAction(final JDialog dialog, KeyStroke keyStroke)
  4. setupOKCancelHotkeys(JDialog dlg, JButton btnOK, final JButton btnCancel)