Here you can find the source of addEscapeKeyCloseAction(final JDialog dialog)
Parameter | Description |
---|---|
dialog | a parameter |
public static void addEscapeKeyCloseAction(final JDialog dialog)
//package com.java2s; /*//w w w .j ava2 s.c o m * Carrot2 project. * * Copyright (C) 2002-2006, Dawid Weiss, Stanis?aw Osi?ski. * Portions (C) Contributors listed in "carrot2.CONTRIBUTORS" file. * All rights reserved. * * Refer to the full license file "carrot2.LICENSE" * in the root folder of the repository checkout or at: * http://www.carrot2.org/carrot2.LICENSE */ import java.awt.event.*; import javax.swing.*; public class Main { /** * Adds to the dialog a key listener that makes the dialog invisible. * * @param dialog */ public static void addEscapeKeyCloseAction(final JDialog dialog) { dialog.getRootPane().registerKeyboardAction(new ActionListener() { public void actionPerformed(ActionEvent e) { dialog.setVisible(false); } }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); } }