Microsoft Windows users are accustomed to pressing the Escape key to close dialog windows. Likewise, the Escape key closes the active dialog in most commercial products, no matter which control of the dialog has the focus. This Java Tip offers an easy way to intercept the Escape-key event in all dialogs of your Java applet or application. Note: This article was updated on March 4 to improve the code's performance. (1,100 words) Plus: Check out our index of previously published tips.
2. Press Escape to close your Swing dialog windows
In a previous Java Tip, you learned how to intercept Escape-key events to close dialog windows for your Java AWT applets and applications. In this tip, we'll see how to do the same thing with JFC/Swing dialog windows. Plus: Check out our index of previously published tips.(700 words)
The standard Java modal and nonmodal dialogs are adequate for most GUIs. However, you may sometimes want to force users to do something within a dialog box (the modal aspect) and at the same time allow them to use the underlying GUI (the nonmodal aspect). The controlled nonmodal part often allows a more natural response to the dialog. This Java Tip presents an approach for creating semimodal dialog boxes that provide both these capabilities simultaneously. (2,500 words)