简体   繁体   English

在Swing中制作F1快捷键

[英]Make F1 short cut key in Swing

I have a Java Swing app in Which I have been able to set shortcut keys using the following piece of code. 我有一个Java Swing应用程序,我可以使用以下代码设置快捷键。 For example Ctrl + K . 例如Ctrl + K.

keyHelp.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_K, Event.CTRL_MASK));
keyHelp.setMnemonic((int) 'K');//This is the Line I need Help in 

I just can't figure out how to add the same using F1 key as the shortcut... Could anyone please help? 我只是无法弄清楚如何使用F1键作为快捷方式添加相同的...有人可以帮忙吗?

Using Action , as shown here and here , can make these settings easier to manage. 使用Action ,如此此处所示,可以使这些设置更易于管理。 Also consider getMenuShortcutKeyMask() instead of assuming Event.CTRL_MASK . 还要考虑getMenuShortcutKeyMask()而不是假设Event.CTRL_MASK

use, 采用,

KeyEvent.VK_F1 KeyEvent.VK_F1

I think it will help you. 我认为它会对你有所帮助。

如果你需要在没有CTRL的情况下将快捷键设为“F1”,它应该是这样的,

keyHelp.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM