Java在jtree上检测CTRL + X组合键 [英] Java detect CTRL+X key combination on a jtree
本文介绍了Java在jtree上检测CTRL + X组合键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一个示例,如何添加一个键盘处理程序来检测 Ctrl + C , Ctrl + X , Ctrl + C 按 JTree
。
I need an example how to add a keyboard handler that detect when Ctrl+C , Ctrl+X , Ctrl+C pressed on a JTree
.
之前我使用菜单快捷键执行此操作但没有成功。
I were do this before with menu shortcut keys but with no success.
推荐答案
您可以将KeyListeners添加到任何组件(f )
You can add KeyListeners to any component (f)
f.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
if ((e.getKeyCode() == KeyEvent.VK_C) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) {
System.out.println("woot!");
}
}
@Override
public void keyReleased(KeyEvent e) {
}
});
这篇关于Java在jtree上检测CTRL + X组合键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文