I’d like my right and left arrow keys to function the same as tab/shift-tab… any thoughts on the best way to do this? Nothing looked obvious to me after searching through the documentation and the forums. I can easily detect that right/left were hit, but not sure how to either re-map that to tab/shift-tab or actually issue my own keypress.
That’s all done quite deeply in the component code, though you could probably rig something up using Component::moveKeyboardFocusToSibling in response to those keys.
Thanks for the tip jules. That method works great on windows, but has a different behavior on mac. On windows it seems to follow the tab order perfectly… on mac the tab key and my right arrow key seem to follow a different order for traversing. This is my code:
else if(key.getKeyCode() == key.rightKey)
else if(key.getKeyCode() == key.leftKey)
Any thoughts on why there would be a different “tab order” in windows and mac when using this method?
No, no idea! None of that stuff uses any platform-dependent code. You’re not just getting double key-presses or something, are you? Maybe using both the key-down and key-up?..
Definitely not getting two keypresses. Let me describe how my components are set up on the page. I have two components each with 3 subcomponents. So if we call the two main components A and B, and the three subcomponents 1, 2, and 3 this is how the screen is laid out:
A.1 A.2 A.3 B.1 B.2 B.3
When pressing tab and shift-tab we correctly traverse from A.1 to A.2 to A.3 to B.1 etc… on windows moveKeyboardFocusToSibling follows this same order. On Mac the tab key traverses properly but moveKeyboardFocusToSibling goes from A.1 to B.1 to A.2 to B.2 to A.3 to B.3.
You’re saying that tab has a different behaviour to moveKeyboardFocusToSibling, but take a look in ComponentPeer, line 456, and you can see that all the tab key does is to call moveKeyboardFocusToSibling!
You must be doing something weird in your code - maybe do some stepping through in the debugger to see what’s really going on there…
I figured it out… In my keyPressed method I wasn’t returning true to “eat” the keystroke after I process it. All is well now