Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to catch key event in JTable

 
Joy Chen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rene
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic