Dialog Default Action

The Microsoft Windows operating environment has the concept of a default button when modal dialog windows are open. The default button is painted in a way that makes it stand out visually to the user. Normally, that is the OK button; however, it can be any action button on the dialog. To handle this concept, the StandardDialog adds entries to the action and input maps of its root pane for handling the enter keystroke.

If your dialog box does not have an OK button or, if at any time, the default button should be some other button, then a call like the following needs to be performed:

dlg.getRootPane().setDefaultButton(closeBtn);