File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

Default Button and Enter Key

J Girl
Greenhorn

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");
getRootPane().setDefaultButton(okButton);
okButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
hide();
if (owner != null)
{
owner.show();
owner.toFront();
}
}
});
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Default Button and Enter Key