🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #262

Re: requestFocus and JTextField

#262
From: Paul Furbacher [TeamB]
Date: Tue, 12 Jun 2007 21:27
48 lines
2705 bytes
Kevin Dean [TeamB] wrote:
> 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:
        http://info.borland.com/newsgroups/ngsearch.html

   Is it in Joi Ellis's Faq-O-Matic?
        http://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.
Technical Details
Message-ID: <466f0fc1$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!feeder3.cambrium.nl!feed.tweaknews.nl!newsfeed0.kamp.net!newsfeed.kamp.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <466ec402$2@newsgroups.borland.com> <xn0f7d6r7cpko2001-kdean@www.teamb.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 111d45,cd79719f41c7c23a
X-Google-Attributes: gid111d45,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Tue, 12 Jun 2007 17:27:35 -0400
From: "Paul Furbacher [TeamB]" <pfurbacher@mac.com>
Organization: Reverse Alchemy, Inc.
User-Agent: Thunderbird 1.5.0.12 (Macintosh/20070509)
MIME-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing
Subject: Re: requestFocus and JTextField
References: <466ec402$2@newsgroups.borland.com> <xn0f7d6r7cpko2001-kdean@www.teamb.com>
In-Reply-To: <xn0f7d6r7cpko2001-kdean@www.teamb.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 69.142.194.228
Message-ID: <466f0fc1$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1181683649 69.142.194.228 (12 Jun 2007 14:27:29 -0700)
Lines: 48
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!feeder3.cambrium.nl!feed.tweaknews.nl!newsfeed0.kamp.net!newsfeed.kamp.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail