I’m finding that keyboard focus is a surprisingly complex beast to tame lately.
I have a component that has several layers of children within it. When any of the children get clicked on, the device as a whole should get focus. There are visual indicators to show whether or not it has focus.
What is the way I should go about this? If i give the component focus, that’s fine - it can respond with its focusGained. However, if I click on one of its children, (e.g. in a contained list - some row components of which also require focus) how am I supposed to let the main component know it should show focus?
Should i just deny all children direct keyboard focus, and instead forward keyPressed() calls to them if they’re not swallowed higher up? Or do I have to at each level notify upwards to the parent so that it might reach the main component? I guess I was a bit naive in thinking that a lot of this was done automatically - either that or i’ve just gone about it the wrong way!
this is the sort of structure i’m working with:
[Outer] - needs left/right keypresses
- [viewport style component] - needs no keypresses
– [listbox] - needs up/down/enter
— [row component] - certain rows require specific keypresses