Here you can find the source of installEscapeCloseOperation(final JDialog dialog)
public static void installEscapeCloseOperation(final JDialog dialog)
//package com.java2s; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import java.awt.event.WindowEvent; import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JRootPane; import javax.swing.KeyStroke; public class Main { private static final KeyStroke ESCAPE_STROKE = KeyStroke.getKeyStroke( KeyEvent.VK_ESCAPE, 0); private static final String DISPATCH_WINDOW_CLOSING_ACTION_MAP_KEY = "com.spodding.tackline.dispatch:WINDOW_CLOSING"; public static void installEscapeCloseOperation(final JDialog dialog) { Action dispatchClosing = new AbstractAction() { private static final long serialVersionUID = 1L; @Override/*from w ww.j a v a 2 s. c o m*/ public void actionPerformed(final ActionEvent event) { dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING)); } }; JRootPane root = dialog.getRootPane(); root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( ESCAPE_STROKE, DISPATCH_WINDOW_CLOSING_ACTION_MAP_KEY); root.getActionMap().put(DISPATCH_WINDOW_CLOSING_ACTION_MAP_KEY, dispatchClosing); } }