I'm trying to cause my JTextField to generate an ActionEvent when I hit Tab just as it does when I hit Enter. I searched for it, and didn't see an apparent solution in the results I looked at(but I didn't read all 166 of them). Is there an easy way to do this that I just missed? It seems like the JTextField is not even ever seeing the tab events at all. I subclassed JTextField and watched the processKeyEvent() method and it never even hit that method when the tab key was pressed. Is the JPanel it's in eating that keypress as part of the focus traversal process? Is there any way force that keypress to show itself to the JTextField?
Now that I can see it, I can work out some way to trigger on it.
Thanks for your help, Chris
Joined: Jun 27, 2000
OK, bonus for anyone looking in here to find a solution. here's how I ended up making this work best. I should have thought of this before, but hey..
David gave me good input, but it ended up being easier to simply set up a focus listener on the JTextField and when tab took the focus away, I did my business with the JTextField content. This makes it work when the mouse clicks away to somewhere else as well. To make this work with the Enter keypress, I used an actionlistener that just called myJTextField.transferFocus(). This makes the Enter keypress act like Tab, moving focus to the next component and in the process activating my focus listener which takes care of the JTextField content.
I have an application with multiple JTextField's each with its own data to be processed and edited.
I have the application working using the Enter key and ActionListener.
I would like it to work with the Tab key as well as the Enter key. Thus when the user entered data and pressed the Tab key,
the application would process the data and move to the next field, just as the Enter key Action Listener code does now.
The information in this post is just what I need.