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

public static void addEscapeListener(final JDialog dialog) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

public class Main {
    public static void addEscapeListener(final JDialog dialog) {
        ActionListener escListener = new ActionListener() {

            @Override//from   w w  w  . jav a2s  . com
            public void actionPerformed(ActionEvent e) {
                dialog.setVisible(false);
            }
        };

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

    }
}

Related

  1. addEscapeExitListeners(final JDialog window)
  2. addEscapeKeyCloseAction(final JDialog dialog)
  3. addEscapeKeyCloseAction(final JDialog dialog)
  4. addEscapeListener(final JDialog dialog)
  5. addEscapeListener(final JDialog dialog)
  6. addEscapeListener(final JDialog dialog, final boolean hide)
  7. addEscapeToCloseSupport(final JDialog dialog)
  8. addEscapeToCloseSupport(final JDialog dialog, final boolean fadeOnClose)
  9. addEscKeyAction(javax.swing.JDialog dialog, javax.swing.Action action)