Here you can find the source of registerEscapeKey(final JDialog dialog, ActionListener actionListener)
public static void registerEscapeKey(final JDialog dialog, ActionListener actionListener)
//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); } }