File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes How to catch key event in JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of RabbitMQ in Depth this week in the Open Source forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to catch key event in JTable" Watch "How to catch key event in JTable" New topic

How to catch key event in JTable

Joy Chen

Joined: Jul 03, 2002
Posts: 3
Hi, all
I add KeyListener to my JTable and hope it can catch the key event such as TAB key or ENTER key pressed. But after I edit one cell and press TAB, it does not fire the KeyEvent, only after I press TAB again, it catch the event and do the relevant business logic.
I wonder why the first TAB key pressed is not caught?
P.S. if I do not edit one cell and press TAB, it will catch the TAB key pressed event.
Rene Liebmann
Ranch Hand

Joined: May 02, 2002
Posts: 196
Hi Joy,
some days ago we had a similar post in this forum. Somebody had the problem, that he was not able to catch TAB key event in JTextField. We found out, that we need to call the method setFocusTraversalKeysEnabled(true) to the JTextField.
I think, the same happens to you, because the JTextField is probably your TableCellEditor.
So it seems to me, that you need to writ your own TableCellEditor, where you call the above mentioned method.
Good Luck
I agree. Here's the link:
subject: How to catch key event in JTable