Why can't I get KeyEvent.VK_TAB when I use Key Binding for a JPanel

前端 未结 3 1736
轻奢々
轻奢々 2021-01-20 22:45

I will print related info if users focus on current window and press a key. However, it works for some keys like \'a\' but not for \'tab\'. Here is a simple demo:

         


        
3条回答
  •  粉色の甜心
    2021-01-20 23:03

    I think it should work if you put

    setFocusTraversalKeysEnabled(false);
    

    in your MainPanel constructor. At least it works for e.g. addKeyListener(...);

提交回复
热议问题