Here you can find the source of escapeKeyAction(JComponent component, javax.swing.AbstractAction abstractAction)
public static void escapeKeyAction(JComponent component, javax.swing.AbstractAction abstractAction)
//package com.java2s; /*//from w ww. j a v a 2s . c o m * codjo.net * * Common Apache License 2.0 */ import java.awt.event.KeyEvent; import javax.swing.JComponent; import javax.swing.KeyStroke; public class Main { static final String ESC_ACTION_KEY = "ESC_ACTION_KEY"; public static void escapeKeyAction(JComponent component, javax.swing.AbstractAction abstractAction) { component.getRootPane().getActionMap().put(ESC_ACTION_KEY, abstractAction); component.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), ESC_ACTION_KEY); } }