如何使“输入”关键行为喜欢提交在JFrame [英] How to make "Enter" Key Behave like Submit on a JFrame

查看:270
本文介绍了如何使“输入”关键行为喜欢提交在JFrame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个客户端/服务器应用程序。
,我想让身份验证框架中的用户轻松。



我想知道如何使进入 - 一个方便的方法依赖于

解决方案 http://download.oracle.com/javase/7/docs/api/javax/swing/JRootPane.html#setDefaultButton%28javax.swing.JButton%29\">setDefaultButton() ,显示在此示例,并在中提及

  JFrame f = new JFrame(Example ); 
Action accept = new AbstractAction(Accept){

@Override
public void actionPerformed(ActionEvent e){
// handle accept
}
};
private JButton b = new JButton(accept);
...
f.getRootPane()。setDefaultButton(b);


I'm Building a Client/Server application. and I want to to make it easy for the user at the Authentication Frame.

I want to know how to make enter-key submits the login and password to the Database (Fires the Action) ?

解决方案

One convenient approach relies on setDefaultButton(), shown in this example and mentioned in How to Use Key Bindings.

JFrame f = new JFrame("Example");
Action accept = new AbstractAction("Accept") {

    @Override
    public void actionPerformed(ActionEvent e) {
        // handle accept
    }
};
private JButton b = new JButton(accept);
...
f.getRootPane().setDefaultButton(b);

这篇关于如何使“输入”关键行为喜欢提交在JFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆