🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Setting Focus Won't Work

#12354
From: Matt Krevs
Date: Thu, 14 Jan 1999 00:00
51 lines
2247 bytes
Firstly, have you added userId to the Dialog before you do all the focus
stuff?

Usually, the component that will initially gain focus is the one that was
added to the container first. Trying adding userId first and see what
happens

Secondly, requestDefaultFocus() doesnt work like its name suggests. Calling
this method means that the component within a container that is the
'default' focus component will get the focus so calling this for a
JTextField will do nothing ( ie there are no further components within the
JTextField ).

I have never had much luck with calling requestFocus() or grabFocus() unless
I use SwingUtilities.invokeLater().

Anyone out there know the ins and outs of focus management?

Paul Waldo wrote in message <369CC78B.CABDD184@bna.com>...
>Hi all,
>
>I'm having a very frustrating problem with focus.  I have created a
>JDialog that has a number of focusable components.  I want to explicitly
>set the focus to a JTextField that does not get the initial focus.  I am
>using the following code:
>
>  JTextField userId = new JTextField(8);
>
>in jbinit ()...
>    System.out.println (userId.isFocusTraversable ());
>    System.out.println (userId.isRequestFocusEnabled ());
>    System.out.println
>(com.sun.java.swing.FocusManager.isFocusManagerEnabled ());
>    System.out.println (getRootPane ().isManagingFocus ());
>    userId.requestDefaultFocus ();
>    userId.requestFocus ();
>    System.out.println (userId.hasFocus ());
>
>The focus never changes to the userId component and the output looks
>like this:
>true
>true
>true
>false
>false
>
>It seems like everything goes OK, but the focus never gets changed.  I'm
>stumped.  Anyone have any ideas?  TIA
>
>Paul Waldo
>
Technical Details
Message-ID: <77j6j1$slg20@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <369CC78B.CABDD184@bna.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,223cd5ce51a082af
X-Google-Attributes: gid111d45,public
From: "Matt Krevs" <mattkrevs@flex.com.au>
Subject: Re: Setting Focus Won't Work
Date: 1999/01/14
Message-ID: <77j6j1$slg20@forums.borland.com>
X-Deja-AN: 432302430
References: <369CC78B.CABDD184@bna.com>
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.swing