File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Default Button and Enter Key

 
J Girl
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic