Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

handling keyTyped events in JTable for TAB key

843806Sep 28 2007 — edited Sep 28 2007
In my app, I have a JTable. Some columns are non-editable.

I have attached a keyListener to the table and have overridden keyTyped() and keyReleased() methods.

In keyReleased(), I do something depending on the key code. For example: if its the VK_DELETE, I delete the row. If its some other user configured key, then I show a popup dialog where the user can enter some data, etc...

In keyTyped(), I first check if the column is one of the specific columns. Then I get the keyChar. After this, I show a dialog and pre-populate a JTextField on this dialog with that keyChar.

My issue is that 'TAB' key events arrive in keyTyped() and not in keyReleased(). As a result, the dialog is shown and the tab takes place inside the JTextfield which is incorrect.

I would like to ignore TAB keyTyped events. When I look up the keyCode in keyTyped() method, it is 0. So there is no way for me to tell what key was typed.

How can I ignore TAB events in my keyTyped() method?

thx
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 26 2007
Added on Sep 28 2007
1 comment
147 views