Java JFrame addEscapeListener(final JFrame frame)

Here you can find the source of addEscapeListener(final JFrame frame)

Description

add Escape Listener

License

Open Source License

Declaration

public synchronized static void addEscapeListener(final JFrame frame) 

Method Source Code

//package com.java2s;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.KeyStroke;

public class Main {
    public synchronized static void addEscapeListener(final JFrame frame) {
        final ActionListener escListener = new ActionListener() {

            @Override/* ww  w.  jav  a  2 s .  c o m*/
            public void actionPerformed(final ActionEvent e) {
                frame.dispose();
            }
        };

        frame.getRootPane().registerKeyboardAction(escListener, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
                JComponent.WHEN_IN_FOCUSED_WINDOW);
    }
}

Related

  1. abrirJFrameCentralizado(JFrame dialog)
  2. activateWindowClosingButton(JFrame frame)
  3. addDisposeActionWithEscapeKey(final JFrame frame)
  4. addEscapeExitListeners(final JFrame window)
  5. addJFrameReporter(JFrame to)
  6. addPanelToFrame(final JFrame frame, final JPanel panel, final String title)
  7. addProgressBar(final JFrame win)
  8. addToQue(JFrame frame)