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

查看:28
本文介绍了通过 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.

查看 输入键和按钮几个解决方案:

  1. 当您从一个按钮切换到另一个按钮时,您可以使用 UIManager 使该按钮成为默认按钮:UIManager.put("Button.defaultButtonFollowsFocus", Boolean.TRUE);

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

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

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

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