๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: JPanel question

#10622
From: Paul Furbacher [TeamB]
Date: Fri, 20 Aug 1999 00:00
43 lines
1858 bytes
Boris Villazรณn wrote:

> I want to know if it is posible that a jpanel can know which component,
> inside it, has the focus.

You could recursively iterate through all of the components owned
by the panel (a container) and ask each whether it has the focus.
This is probably not a good approach.  Suppose your panel is 
just one of a number in a window (JFrame, Frame, DecoratedFrame, 
etc.).  And suppose that the focus is held by some other component
in some other panel.  If you are ultimately seeking who has the 
focus, you'd miss it if you were just looking "inside" the panel.

A better approach would be to get the window which owns the
particular panel you are interested in (if you don't already know it).

  Window window = myPanel.getWindow(); 

Then, if window != null, ask

  Component c = window.getFocusOwner();

Once you have the component, you could then see if it is 
contained in your panel:

  boolean isInMyPanel = ( myPanel.isAncestorOf(c) );

[I have to say that I've never liked this usage of "Ancestor" in the AWT.  
View hierarchy is not the same as ancestry, which to me applies to 
class hierarchy.  Maybe someone can persuasively argue for such 
usage?]

Paul Furbacher  (TeamB)
Technical Details
Message-ID: <37BE1678.3897D6F4@bilbo.bio.purdue.edu>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <37BD592A.4E21154F@ucbcba.edu.bo>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 111d45,3cb337eaf0ef1218
X-Google-Attributes: gid111d45,public
From: "Paul Furbacher [TeamB]" <pf@bilbo.bio.purdue.edu>
Subject: Re: JPanel question
Date: 1999/08/20
Message-ID: <37BE1678.3897D6F4@bilbo.bio.purdue.edu>
X-Deja-AN: 515357039
Content-Transfer-Encoding: quoted-printable
References: <37BD592A.4E21154F@ucbcba.edu.bo>
Content-Type: text/plain; charset=iso-8859-1
Organization: Reverse Alchemy, Inc.
Mime-Version: 1.0
Reply-To: pf@bilbo.bio.purdue.edu
Newsgroups: borland.public.jbuilder.java.swing