0

Okay, you know when on like an alert window, or a form, one of the buttons automatically gets executed when you press enter, such as shown. See Picture #1

So I was wondering how I could do this in Java for a both a JFrame and a JOptionPane. Thanks.

arithehun

Picture #1

Edited by arithehun: n/a

Attachments picture1.png 32.61 KB
1
Contributor
1
Reply
3
Views
7 Years
Discussion Span
Last Post by arithehun
0

Never mind, I figured it out. In your constructor, post the following code, and replace "buttonName" with the name of a JButton:

getRootPane().setDefaultButton(buttonName);

Edited by arithehun: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.