Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a JDialog button respond to the Enter key

I have a JQueryDialog with a text field, an OK button and a cancel button.

I want to be able to hit the enter key after filling in the text fields and have it do the same action as when I click the OK button.

like image 780
Ben Noland Avatar asked Dec 05 '08 20:12

Ben Noland


People also ask

How do I open JDialog in center of screen?

If you really want to center a JDialog on screen, you can use code like this: // center a jdialog on screen JDialog d = new JDialog(); d. setSize(400, 300); d. setLocationRelativeTo(null); d.

Where is JDialog used in an application?

JDialog is one of the important features of JAVA Swing contributing to interactive desktop-based applications. This is used as a top-level container on which multiple lightweight JAVA swing components can be placed to form a window based application.

What is JDialog?

JDialog is a part Java swing package. The main purpose of the dialog is to add components to it. JDialog can be customized according to user need . Constructor of the class are: JDialog() : creates an empty dialog without any title or any specified owner.


1 Answers

In your dialog, call getRootPane().setDefaultButton(okButton).

like image 145
Jason Day Avatar answered Oct 21 '22 08:10

Jason Day