Article View: borland.public.jbuilder.java.swing
Article #11284Re: Problems with requestFocus() and requestDefaultFocus()
From: Max Polk
Date: Tue, 15 Jun 1999 00:00
Date: Tue, 15 Jun 1999 00:00
30 lines
1652 bytes
1652 bytes
In article <7k6l3o$l2i10@forums.borland.com>, mattkrevs@flex.com.au
says...
> Unfortunately, I have found setting initial focus to be far from simple. The
> following code should work
>
> SwingUtilities.invokeLater
> (
> new Runnable()
> {
> public void run()
> {
> // Set focus to the component
> theComponent.requestFocus();
> }
> }
> );
This is one way to do this. Realize that when you are creating some
visual component, it isn't even displayed yet! KEEP THAT IN MIND! Since
it is not even displayed yet, commands to request the focus AREN'T EVEN
MEANINGFUL. How can you request focus on something that is not even
visible yet?
The above code is a trick to request focus a bit later. Realize that
this may not work either on occasion because this tacks on a bit of code
at the end of a the event-dispatching queue. Unless your component is
visible at the time the above code executes, you are out of luck.
Another way to do this whole thing is to wait for focus to be established
after it is made visible, then move focus where you want at that time.
Technical Details
Message-ID:
<MPG.11d0d6605944f1cc9896f9@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<7k4us1$jms6@forums.borland.com> <7k6l3o$l2i10@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,a26bf9823a51282e X-Google-Attributes: gid111d45,public From: none@none.invalid (Max Polk) Subject: Re: Problems with requestFocus() and requestDefaultFocus() Date: 1999/06/15 Message-ID: <MPG.11d0d6605944f1cc9896f9@forums.borland.com> X-Deja-AN: 490085051 References: <7k4us1$jms6@forums.borland.com> <7k6l3o$l2i10@forums.borland.com> Organization: Another Netscape Collabra Server User Newsgroups: borland.public.jbuilder.java.swing