Java JDialog Escape Key addEscapeListener(final JDialog dialog)

Here you can find the source of addEscapeListener(final JDialog dialog)

Description

add Escape Listener

License

Open Source License

Declaration

static public void addEscapeListener(final JDialog dialog) 

Method Source Code

//package com.java2s;
// This copy of Ice is licensed to you under the terms described in the

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.JDialog;
import javax.swing.JComponent;
import javax.swing.KeyStroke;

public class Main {
    static public void addEscapeListener(final JDialog dialog) {
        dialog.getRootPane().registerKeyboardAction(new ActionListener() {
            @Override//from   w ww  .  java  2s  .c o m
            public void actionPerformed(ActionEvent e) {
                dialog.dispose();
            }
        }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
    }
}

Related

  1. addDisposeOnEscape(final JDialog dia)
  2. addEscapeExitListeners(final JDialog window)
  3. addEscapeKeyCloseAction(final JDialog dialog)
  4. addEscapeKeyCloseAction(final JDialog dialog)
  5. addEscapeListener(final JDialog dialog)
  6. addEscapeListener(final JDialog dialog)
  7. addEscapeListener(final JDialog dialog, final boolean hide)
  8. addEscapeToCloseSupport(final JDialog dialog)
  9. addEscapeToCloseSupport(final JDialog dialog, final boolean fadeOnClose)