Java JDialog Escape Key registerEscapeKey(final JDialog dialog, ActionListener actionListener)

Here you can find the source of registerEscapeKey(final JDialog dialog, ActionListener actionListener)

Description

register Escape Key

License

Open Source License

Declaration

public static void registerEscapeKey(final JDialog dialog, ActionListener actionListener) 

Method Source Code


//package com.java2s;
/*//from w w w.j a va  2 s.c  o  m
 * Copyright (c) Mirth Corporation. All rights reserved.
 * http://www.mirthcorp.com
 * 
 * The software in this package is published under the terms of the MPL
 * license a copy of which has been included with this distribution in
 * the LICENSE.txt file.
 */

import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.KeyStroke;

public class Main {
    public static void registerEscapeKey(final JDialog dialog, ActionListener actionListener) {
        dialog.getRootPane().registerKeyboardAction(actionListener, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
                JComponent.WHEN_IN_FOCUSED_WINDOW);
    }
}

Related

  1. enableCloseByEscape(final JDialog dialog)
  2. installEscapeCloseOperation(final JDialog dialog)
  3. installEscapeCloseOperation(final JDialog dialog)
  4. installEscapeCloseOperation(final JDialog dialog)
  5. installEscapeKey(final JDialog comp)
  6. setEscapeAction(JDialog dialog, Action action)
  7. setEscapeClosable(JDialog dialog)