Here you can find the source of configureOKAndCancelButtons(JPanel panel, Action ok, Action cancel)
public static void configureOKAndCancelButtons(JPanel panel, Action ok, Action cancel)
//package com.java2s; // License: Apache Software License (Version 2.0) import java.awt.event.KeyEvent; import javax.swing.Action; import javax.swing.ActionMap; import javax.swing.InputMap; import javax.swing.JComponent; import javax.swing.JPanel; import javax.swing.KeyStroke; public class Main { public static void configureOKAndCancelButtons(JPanel panel, Action ok, Action cancel) { final ActionMap actionMap = panel.getActionMap(); final InputMap inputMap = panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); if (cancel != null) { actionMap.put(cancel.getValue(Action.ACTION_COMMAND_KEY), cancel); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancel.getValue(Action.ACTION_COMMAND_KEY)); }/*from w ww .java 2 s . co m*/ if (ok != null) { actionMap.put(ok.getValue(Action.ACTION_COMMAND_KEY), ok); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), ok.getValue(Action.ACTION_COMMAND_KEY)); } } }