List of usage examples for javax.swing JFrame getWindowListeners
public synchronized WindowListener[] getWindowListeners()
From source file:Main.java
/** * Attaches a key event listener to given component, disposing of the given window * upon pressing escape within the context. * /*from w w w. j a v a 2s .com*/ * @param context * @param button */ public static void simulateExitOnEscape(Component context, JFrame window) { context.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { for (WindowListener wl : window.getWindowListeners()) { wl.windowClosing(new WindowEvent(window, WindowEvent.WINDOW_CLOSING)); } if (window != null) window.dispose(); } } }); }