Article View: borland.public.jbuilder.java.swing
Article #8403Re: GetFocus()
From: John P. McGrath
Date: Tue, 19 Sep 2000 00:00
Date: Tue, 19 Sep 2000 00:00
31 lines
1745 bytes
1745 bytes
On Sun, 17 Sep 2000 05:44:09 -0500, Shane Stump wrote:
> Anyway, I am assuming there is no equivalent to the GetFocus()
> command other than to track events myself within the app!
I am not very familiar with the Win32 API (presuming that is what
GetFocus() is from), but since you talk about tracking events I am
guessing that it determines which component has the focus.
If that is what you are asking, then there is a better way. The Window
class has a getFocusOwner() method that will return the child component
of the Window that owns the focus.
From a Swing app, you can use the JComponent getTopLevelAncestor() method
to find the Window that contains a specific component. Note that this
method returns a Container, since the "top level ancestor" can be either
an Applet or a Window.
It is interesting to compare the names of the methods in the Win32 and
Java APIs. There is not much question in my mind which naming is better:
To request that a component be given focus:
Win32: SetFocus() Java: requestFocus()
To get the component that owns the focus:
Win32: GetFocus() Java: getFocusOwner()
--
Regards,
John McGrath
Technical Details
Message-ID:
<MPG.1430e3b0eb523caa989b4d@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<39c023b6$1_1@dnews> <39c33836$1_1@dnews> <39c35bc9$1_1@dnews> <MPG.142e431c96622a28989b45@forums.borland.com> <39c49e72$1_2@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,5fce9644c11175fd X-Google-Attributes: gid111d45,public From: John P. McGrath <JPMcGrath@fast.net> Subject: Re: GetFocus() Date: 2000/09/19 Message-ID: <MPG.1430e3b0eb523caa989b4d@forums.borland.com> X-Deja-AN: 671528688 References: <39c023b6$1_1@dnews> <39c33836$1_1@dnews> <39c35bc9$1_1@dnews> <MPG.142e431c96622a28989b45@forums.borland.com> <39c49e72$1_2@dnews> Organization: Another Netscape Collabra Server User Newsgroups: borland.public.jbuilder.java.swing