As stated, I want to change the default TAB behaviour within a JTextArea (so that it acts like a JTextField or similar component)
Here’s the event action
private void diagInputKeyPressed(java.awt.event.KeyEvent evt) { if(evt.KEY_PRESSED == java.awt.event.KeyEvent.VK_TAB) { actionInput.transferFocus(); } }
And here’s the listener
diagInput.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(java.awt.event.KeyEvent evt) { diagInputKeyPressed(evt); } });
I’ve tried evt.KEY_TYPED as well with no joy.
Any ideas?
quick edit: I’ve also tried requestFocus() in place of transferFocus()
According to this class:
Note that
patch()can be even shorter, according to Joshua Goldberg in the comments, since the goal is to get back default behaviors overridden byJTextArea:This is used in question ‘How can I modify the behavior of the tab key in a
JTextArea?‘The previous implementation involved indeed a
Listener, and the atransferFocus():e.consume();might have been what you missed to make it work in your case.