Mitch Weaver Mitch Weaver - 2 years ago 84
Java Question

Adding TAB key java swing keybindings --- What is the correct name?

Action tab = new AbstractAction() {
public void actionPerformed(ActionEvent e) {

Game.panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("Tab"), "tab");
Game.panel.getActionMap().put("tab", tab);

However its not printing. This is the same set up that I use for all my other keys, but I can't get the tab key to work. I've tried
, and

What's the correct name for it? Or is there something special?

Answer Source

You probably want:


\t is the escape sequence for the TAB character (0x09), which is output by pressing tab on your keyboard.

There is also KeyEvent.VK_TAB which might be preferable depending on your use case. See the documentation in KeyEvent for more on why you should prefer one or the other.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download