When does focus change?

I’ve added a TextEditor object that allows the user to change the text of a tab label. It floats right above the tab label until the the user hits return (to confirm the change), escapes out, or the label loses focus.

I had thought that focus on the TextEditor would be lost if the user clicked
anywhere else in the interface. This doesn’t appear be the case. I can start editing one tab label, then click on the next tab over, and the TextEditor keeps floating where it was, with no call to it’s textEditorLostFocus() routine.

Is there a way to tell when the user has clicked outside this component, so I can remove it?

Focus will only be lost when another comp becomes focused, so clicking somewhere that doesn’t want focus won’t get rid of it. I’m a bit surprised that you’re not getting focus loss events when another text editor appears, so I’ll look into that.

But the best way to do this kind of thing is to make the text editor modal, then override its inputAttemptWhenModal() method to find out when the user tries to click somewhere else. Or better still, just use the Label class instead, which does all of this for you.

Subclassing TextEditor to delete itself in inputAttemptWhenModal() worked out perfectly. Thanks!

In the previous scenario, creating a new TextEditor would cause focus to change, so there’s no bug there to be found.

I started off trying to do this with a floating Label, but I wanted to delete the label when the user hit escape in textEditorEscapeKeyPresed(). Deleting the Label in that function makes the Label unhappy.