Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Default Button and Enter Key  RSS feed

J Girl
Posts: 1
  • 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");
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?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!