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?


基础教程推荐
- 如何强制对超级方法进行多态调用? 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01