doesn't work. I'm stumped. I want to use tab! Googling KeyStroke TAB came up with several examples of people using it, so I know the string is tab. I know my tab key works. If there's any other information that would be useful, I can provide it, but I don't know what would be pertinent.
I've heard it takes forever to grow a woman from the ground
Binding the tab key is more complex than the others. JTextComponents have a tab key binding for adding tabs in JTextArea nad other components by design. Containers use the tab key for keyboard navigation among child components. To successfully use a tab key binding you have to remove the default key bindings that may exist on other key maps for a component. How to Use Key Bindings
Craig, if Nick were working with a JTextComponent as you assume, he wouldn't be having this problem. His code does replace the existing TAB key binding with his own. But most other components use the TAB key for focus traversal, and that means the InputMaps never see the keystroke. You can disable keyboard focus traversal (or assign different keys to it) with the setFocusTraversalKeys method.
(Heh! I didn't think that link would work, but you get the idea.) [ November 14, 2005: Message edited by: Alan Moore ]
Joined: Apr 04, 2004
Thanks a lot. For what it's worth, it's a good old fashioned JComponent.
I have an application with two JTextFields. The program was working using Action Listener and the Enter
key to update the data from the JTextField into the work fields for SQL update.
I wanted to use the tab key to exit from the field and update the data and also move to the next JTextField.
I read the Tutorial on Key binding. I thought it started well but quickly dived too deep and never gave a close
example to my problem. I have read this JavaRanch topic and also the referenced Java topic. The referenced Java topic is not
helpful. I understand the words but the usage part is missing.
Here are my code examples for one of the two JTextFields:
Changing the data in the JTextField and pressing Enter works.
Changing the data and pressing the tab key does not. The System.out.println does
not print when you press the Tab key. I changed the TAB key to
F3 like the first entry in this topic. And that did not work either.
So obviously I have a programming error.
What is the correct code please?