//you may press ESCAPE key to close this window.
KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
this.getRootPane().registerKeyboardAction(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
}, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
this.getRootPane().registerKeyboardAction(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
}, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
这是一种自己做响应事件,另外,jDialog应该自己带有这种方法,只是那个方法或者属性设置一下就可以的,只苦于现在还没有找到