Quick and easy question... So I have my QuestionBuilder which I have been asking about, and things are going great. However, I'd like to give users the option to use the Tab key to quickly jump from box to box, button to button.
I made a KeyListener class and was working on it, until I realized that using tab to switch focus was already part of JTextFields and JButtons... all this work on a Listener for nothing!
Except JTextArea creates an indent when I press Tab, it does NOT change focus. So is there an easier way to maybe... I dunno... disable indenting and make the Tab key work like normal?
Is there some secret 'disableIndent()' method somewhere or something?
First of all you should not be using a KeyListener to even attempt to change this. You should be using Key Bindings. Key Bindings explains why the Tab character is inserted into the text area.
Read the section from the Swing tutorial on "How to Use Key Bindings". While your at it read the section on "How to Use the Focus Subsystem", which gives background information about why the solution below works:
Yeah, I knew I shouldn't use KeyListeners right after I attempted it--sorry if I didn't make that clear.
Also, I read all about the focus subsystem but didn't see a clear answer, so thank you for including the bit about Key Bindings. I must have looked over it or not read what I needed to read--there was a lot of text. :/
By default, swing enabled focus on the components to switch one component to another using tab. so until or unless if each component setFocusable is true. This concept will work fine