focusOfChildComponentChanged behavior


Hi I have a question regarding Component::focusOfChildComponentChanged()


I have component which contains TextEditor component. I have overloaded the focusOfChildComponentChanged  in the parrent component. The problem is that it is not called when I change the focus (by mouse click) from the TextEditor to the parrent component. It only gets called if the focus changes to other components that are not either the parrent component or it's children. Is this intentional?




Well, yes. If you read its description, that's exactly what it's supposed to do.


Called to indicate that one of this component's children has been focused or unfocused.

Not quite. I have the TextEditor focused and type something. Then I click the parrent component which makes the TextEditor lose the focus. I can confirm that visualy because it's carret is now gone and I cannot type into it anymore. Therefore it's focus changes. BUT the focusOfChildComponentChanged() is not called. I think that does contradict the description.


Well that's just the title - below it explains:

        Essentially this means that the return value of a call to hasKeyboardFocus (true) has
        changed. It happens when focus moves from one of this component's children (at any depth)
        to a component that isn't contained in this one, (or vice-versa).

So if the focus moves from your text editor to another component inside the parent (or the parent itself), then it won't get called.


Hmm... So if I need to detect the case where one of my child components (one particular TextEditor) loses it's keyboard focus, do I have to inherit the TextEditor and override it's focusLost()?


You could use a FocusChangeListener?


I could but it seems that inheriting is better and simpler for my purpose. Thanks, problem's solved.