public static void addEscapeToCloseSupport(final JDialog dialog,
			final boolean fadeOnClose) {
		LayerUI<Container> layerUI = new LayerUI<Container>() {
			/**
			 * 
			 */
			private static final long serialVersionUID = 2514339457426555702L;
			private boolean closing = false;

			@Override
			public void installUI(JComponent c) {
				super.installUI(c);
				((JLayer<?>) c).setLayerEventMask(AWTEvent.KEY_EVENT_MASK);
			}

			@Override
			public void uninstallUI(JComponent c) {
				super.uninstallUI(c);
				((JLayer<?>) c).setLayerEventMask(0);
			}

			@Override
			public void eventDispatched(AWTEvent e,
					JLayer<? extends Container> l) {
				if (e instanceof KeyEvent
						&& ((KeyEvent) e).getKeyCode() == KeyEvent.VK_ESCAPE) {
					if (closing)
						return;
					closing = true;
					if (fadeOnClose)
						fadeOut(dialog);
					else
						dialog.dispose();
				}
			}
		};

		JLayer<Container> layer = new JLayer<>(dialog.getContentPane(), layerUI);
		dialog.setContentPane(layer);
	}