public static void closeOnEscape(final JDialog dialog){
  closeOnEscape(dialog,dialog.getRootPane());
}

public static void closeOnEscape ( final JDialog dialog ) { closeOnEscape ( dialog , dialog . getRootPane ( ) ) ; }
make the dialog close when the used presses escape . the event will be the same as when the user closes the window using the window manager .
