File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Default Button and Enter Key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Default Button and Enter Key" Watch "Default Button and Enter Key" New topic

Default Button and Enter Key

J Girl

Joined: Apr 08, 2004
Posts: 1
I have a dialogA which is open on top of another dialogB. Both are subclasses of javax.swing.JDialog. DialogB is set to be the owner of dialogA. Both dialogs have a default button defined using the following code snippet:
JButton okButton = new JButton("OK");
okButton.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
if (owner != null)
The okButton works fine if clicked by the mouse. However, if the Enter key is pressed it cascades through both of the dialogs. In other words, when the user hits Enter it invokes the default button of dialogA - which is fine. But it also invokes the default button of the owner dailogB. Is there a way of preventing the Enter key from penetrating through the dialogs?
wood burning stoves
subject: Default Button and Enter Key
jQuery in Action, 3rd edition