Triggering JButtons via ENTER key?(通过 ENTER 键触发 JButtons?)
问题描述
我正在为我的数据库开发 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 键时执行相同操作的侦听器.谢谢
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 键调用按钮的 Action 是 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.
查看 输入键和按钮几个解决方案:
当您从一个按钮切换到另一个按钮时,您可以使用 UIManager 使该按钮成为默认按钮:
UIManager.put("Button.defaultButtonFollowsFocus", Boolean.TRUE);
您可以使用键绑定来映射 Enter Key 按下/释放事件.
You can use Key Bindings to map the Enter Key pressed/released events.
这篇关于通过 ENTER 键触发 JButtons?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:通过 ENTER 键触发 JButtons?


- 未找到/usr/local/lib 中的库 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- 转换 ldap 日期 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01
- 获取数字的最后一位 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01