通过ENTER键触发JButton? [英] Triggering JButtons via ENTER key?

查看:62
本文介绍了通过ENTER键触发JButton?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的数据库开发GUI设计.

I'm developing the GUI design for my database.

在设计了大多数框架并对其进行调试后,我释放了我,需要使用 ENTER 键(而不是仅单击它)将选项添加到触发"按钮.

After designing most of the frame and debugging them I released I needed to add the option to 'trigger' buttons using ENTER key, instead of only clicking on it.

我应该怎么做?我当前正在为按钮使用 MouseListener ,并希望添加一个在按下ENTER键时执行相同操作的Listener.谢谢

How should I go about it? I'm currently using MouseListener for my buttons and want to add a Listener that performs the same actions when ENTER key is pressed. Thank you

推荐答案

使用Enter键调用按钮的动作是LAF问题. Windows支持此功能,但是在默认的Metal LAF中,您使用空格键.

Using the Enter key to invoke the Action of a button is a LAF issue. This is supported in Windows, but in the default Metal LAF you use the space bar.

检出输入键和按钮几个解决方案:

  1. 您可以使用UIManager将按钮设为从按钮到按钮的默认按钮:UIManager.put("Button.defaultButtonFollowsFocus", Boolean.TRUE);

您可以使用键绑定来映射Enter键的按下/释放事件.

You can use Key Bindings to map the Enter Key pressed/released events.

这篇关于通过ENTER键触发JButton?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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