At 11:14 PM 12/12/2001 -0600, Bill Tschumy wrote:

>Now for the slightly harder one.  You need to delay your requestFocus() 
>until the system has already tried to focus on what it thinks should be 
>focused.  What I generally do is implement a WindowListener and in the 
>windowActivated (or windowOpened), do the requestFocus().  But wait!  That 
>still doesn't work.  You need to delay it even further.  In the 
>windowActivated method you need to create a Runnable class that does the 
>requestFocus in the run() method.  Then (again in the windowActivated) you 
>do a SwingUtilities.performLater(myRunnable).  This always delays the call 
>enough so no one else overrules you.

To quote my German teacher: "And you meant to say..."
SwingUtilities.invokeLater(myRunnable).  Other than that,
you're right on...

In fact, this is the standard method I use for setting focus.
I try not to rely on adding the right component first, because
it imposes restrictions on how I add components to my
container, which may conflict with making the code readable.
Plus, as you say, Java might be using that top-left rule anyway.

I haven't yet played with 1.4, which I know has a much more
robust architecture for managing focus.  It might be different
there.

_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing

Reply via email to