grabKeyboardFocus question

I have a dialog with a TextEditor in it. I’d like the TextEditor to have keyboard focus when the dialog shows. The code to invoke the dialog looks like this

DialogWindow    theDialog(T("foo"), Colours::silver, false, true);
MyContentComp  theContent;

As others have pointed out, I can’t call grabKeyboardFocus() on the TextEditor in the MyContentComp constructor, as the dialog isn’t visible yet. I tried calling it in the visibilityChanged() method of MyContentComp, this is called as a result of setContentComponent(), but when runModalLoop() is called, the dialog steals the keyboard focus. At that point, I’m not sure how to get it back.

What’s the best way to make this happen?
It might be nice to have a call like SetLatentKeyboardFocus(), which would allow a component to specify what should become focused when it becomes visible, although that won’t help in this case.

Posted too soon. All this keyboard focus mess is avoided if I show the window, and then call runModalLoop() on the contentComponent.