Java detect CTRL+X key combination on a jtree

后端 未结 5 1140
隐瞒了意图╮
隐瞒了意图╮ 2020-12-11 01:02

I need an example how to add a keyboard handler that detect when Ctrl+C , Ctrl+X , Ctrl+C pressed on a

5条回答
  •  佛祖请我去吃肉
    2020-12-11 01:21

        initComponents();
          KeyboardFocusManager ky=KeyboardFocusManager.getCurrentKeyboardFocusManager();
    
        ky.addKeyEventDispatcher(new KeyEventDispatcher() {
    
            @Override
            public boolean dispatchKeyEvent(KeyEvent e) {
    
                 if (e.getID()==KeyEvent.KEY_RELEASED && (e.getKeyCode() == KeyEvent.VK_C) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) {
                    System.out.println("Dhanushka Tharindu");
                }
                 return  true;
            }
        });
    

提交回复
热议问题