How to return keyboard focus to the previous Component in parent hierarchy?

How to pass keyboard focus back to the previous Component in parent hierarchy which had it before?

My situation is this:
I have a Component which contains couple of hierarchies of child Components.
Some of the components deeper inside those hierarchies are juce::Labels.
I want to click those Labels with mouse, edit the text. Hit enter and then the focus should automatically return back to the Component which owns those Component hierarchies.
Currently what happens is that the focus doesn’t go back to the previously focused Component which owns those child hierarchies. I have to click that component with mouse before it’s in focus again and it starts responding to my keyboard presses.

What’s the proper way of fixing this so the owner Component in the parent hierarchy gets its focus back again?

I just ended up keeping track which Component was in focus on the screen at any given time. And when Label::onEditorHide gets called, I just send a message which handles regaining the focus on the previously used Component.

1 Like