Board index » jbuilder » requestFocus and JTextField

requestFocus and JTextField


2007-06-13 12:04:25 AM
jbuilder1
To all;
I'll be dammed if I can get Focus on a JTextField at Load Time.
I've tried everything(it seems). requestFocus, requestFocusInWindow,
requestFocus(true)....
I have two JDialog's, one with a JList, and one without. The one without
works fine. One of the symptoms is that when I key something in, just after
load time, I
get an "valueChanged" from the ListSelectionListener.
I put a "requestFocus()" then a getFocusOwner() after the init is complete.
The
getFocusOwner() shows "null".
Like I say, it seems as if I have tried everything and read everything I
can get
my hands on... So far no luck..
Bruce Houghton
 
 

Re:requestFocus and JTextField

Bruce Houghtron wrote:
Quote
I'll be dammed if I can get Focus on a JTextField at Load Time.
I've tried everything(it seems). requestFocus, requestFocusInWindow,
requestFocus(true)....
I have two JDialog's, one with a JList, and one without. The one without
works fine. One of the symptoms is that when I key something in, just
after load time, I
get an "valueChanged" from the ListSelectionListener.

I put a "requestFocus()" then a getFocusOwner() after the init is
complete. The
getFocusOwner() shows "null".
Like I say, it seems as if I have tried everything and read everything I
can get
my hands on... So far no luck..
The problem is that requesting focus is a window event and the window
object hasn't been created yet. Initializing a dialog or a frame creates
only the Java objects, not the window handle.
Try hooking into the "componentShown" event on the window and requesting
focus at that point.
--
Kevin Dean [TeamB]
Dolphin Data Development Ltd.
www.datadevelopment.com/
Please see Borland's newsgroup guidelines at
info.borland.com/newsgroups/guide.html
 

Re:requestFocus and JTextField

Damit your good. Thanks allot, I've been fighting this
problem for a long time. Now I can also fix my Login
screen. The customer always asked why I couldn't put
the cursor in the Password Field on the Login screen
Thanks again...
Bruce Houghton
"Kevin Dean [TeamB]" < XXXX@XXXXX.COM >wrote in message
Quote
Bruce Houghtron wrote:

>I'll be dammed if I can get Focus on a JTextField at Load Time.
>I've tried everything(it seems). requestFocus, requestFocusInWindow,
>requestFocus(true)....
>I have two JDialog's, one with a JList, and one without. The one without
>works fine. One of the symptoms is that when I key something in, just
>after load time, I
>get an "valueChanged" from the ListSelectionListener.
>
>I put a "requestFocus()" then a getFocusOwner() after the init is
>complete. The
>getFocusOwner() shows "null".
>Like I say, it seems as if I have tried everything and read everything I
>can get
>my hands on... So far no luck..

The problem is that requesting focus is a window event and the window
object hasn't been created yet. Initializing a dialog or a frame creates
only the Java objects, not the window handle.

Try hooking into the "componentShown" event on the window and requesting
focus at that point.

--
Kevin Dean [TeamB]
Dolphin Data Development Ltd.
www.datadevelopment.com/

Please see Borland's newsgroup guidelines at
info.borland.com/newsgroups/guide.html
 

{smallsort}

Re:requestFocus and JTextField

Kevin Dean [TeamB] wrote:
Quote
Bruce Houghtron wrote:

>I'll be dammed if I can get Focus on a JTextField at Load Time.
>I've tried everything(it seems). requestFocus, requestFocusInWindow,
>requestFocus(true)....
>I have two JDialog's, one with a JList, and one without. The one without
>works fine. One of the symptoms is that when I key something in, just
>after load time, I
>get an "valueChanged" from the ListSelectionListener.
>
>I put a "requestFocus()" then a getFocusOwner() after the init is
>complete. The
>getFocusOwner() shows "null".
>Like I say, it seems as if I have tried everything and read
>everything I can get
>my hands on... So far no luck..

The problem is that requesting focus is a window event and the window
object hasn't been created yet. Initializing a dialog or a frame
creates only the Java objects, not the window handle.

Try hooking into the "componentShown" event on the window and requesting
focus at that point.
The old way of doing this was to override addNotify(). One has to be
careful to call super.addNotify(), otherwise there's trouble.
public void addNotify() {
super.addNotify();
myTextField.requestFocus();
}
--
Paul Furbacher (TeamB)
Save time, search the archives:
info.borland.com/newsgroups/ngsearch.html
Is it in Joi Ellis's Faq-O-Matic?
www.visi.com/~gyles19/fom-serve/cache/1.html
Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.