设立JFrame的缺省JButton

设置JFrame的缺省JButton

设置一个JFrame的缺省JButton。

例如:在登录时,输入完用户名密码后,直接点击回车键就会触发登录按钮的事件。

代码如下:

this.getRootPane().setDefaultButton(loginBtn);

 

this:是指JFrame的子类

loginBtn:指定的按钮