🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Where is focus?

#13044
From: Paul Furbacher
Date: Mon, 28 Sep 1998 00:00
48 lines
2423 bytes
Vasudevan Srinivasan wrote:

> How/When does requestFocus() work?
> [...]

Until a component is "realized", "requestFocus()"
has no effect.  A component is "realized" when its
peer is constructed, and this typically occurs 
when either "addNotify()" is called, or a component
is made visible.  Even Swing components have peers,
called LightweightPeers.  And finally components
nested in frames aren't realized until their owning
containers are realized.  So....

There are a number of schemes aimed at attempting
to get "requestFocus()" to be effective.

1. Place the request in your frame/dialog's "addNotify()".
   Be sure to call "super.addNotify()" in your override,
   before you invoke "requestFocus()".  Not guaranteed
   to work (at least I seem to recall this didn't always 
   work for me).

2. Place the request in the "componentShown" event handler.
   Not guaranteed to work.

3. Make sure the component is the first added to the view 
   hierarchy.  You may also have to disable the Swing 
   FocusManager, but not sure.


Other problems related to focus (you really have to wonder
how the AWT folks botched this so badly), such as restoring
focus when a frame is re-activated/made top window, appear
to have no reliable solution.   When our QA tester noted this 
problem (I was hoping they'd somehow overlook it) I spent a 
good part of a morning about a month ago trying to devise 
some system to handle this properly.

I gave up simply because nothing short of re-inventing the
focus manager was likely to solve the problem.  I had 
more important things to worry about, such as getting the
project out the door and onto bookstore shelves.

Good luck.


Paul Furbacher
Technical Details
Message-ID: <360FBBDB.DC340877@bilbo.bio.purdue.edu>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <360AB611.1D3BB742@swarc.com> <360B0D63.A905B78A@bilbo.bio.purdue.edu> <360BB18A.1D99BEED@netrisk.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,1f6f9d6585b5c186
X-Google-Attributes: gid111d45,public
From: Paul Furbacher <pf@bilbo.bio.purdue.edu>
Subject: Re: Where is focus?
Date: 1998/09/28
Message-ID: <360FBBDB.DC340877@bilbo.bio.purdue.edu>
X-Deja-AN: 395666032
Content-Transfer-Encoding: 7bit
References: <360AB611.1D3BB742@swarc.com> <360B0D63.A905B78A@bilbo.bio.purdue.edu> <360BB18A.1D99BEED@netrisk.com>
To: Vasudevan Srinivasan <vasudevan@netrisk.com>
Content-Type: text/plain; charset=us-ascii
Organization: Biological Sciences, Purdue Univ.
Mime-Version: 1.0
Reply-To: pf@bilbo.bio.purdue.edu
Newsgroups: borland.public.jbuilder.java.swing