Hi, this has had me stumped for the last couple of days.
Here’s what I want to achieve:
I have a parent component as a “canvas” on which child components can be placed. If I dynamically create a new child component, it should be brought to the front, and given keyboard focus. The component with keyboard focus needs to be highlighted (with for example a red rectangle, in its paint() method). Clicking on child components should also bring them to the front and give them keyboard focus and also highlight them.
I have tried so many things, but have failed to get it to work properly yet. It often seems that I need to click twice, or actually move the child components to get them to respond properly.
I have tried so many different things with focusChangedListener, setWantsKeyboardFocus(), grabKeyboardFocus; explicitly setting focus order, setting timers to check that components are showing…etc
But almost always seem to need to click twice or move the child components before the highlight gets drawn on the correct component, and that component receives keyboard focus.