Question: how to close jdialog in java swing?
Answer: JButton myButton = new JButton("Close"); myButton. addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dispose(); // Or whatever else setVisible(false); } }); getRootPane(). setDefaultButton(myButton); That way, its ActionListener will be called whenever Enter is pressed.