Article View: borland.public.jbuilder.java.language
Article #17137Re: Find out which componet currently has focus
From: William Yu
Date: Sat, 12 Dec 1998 00:00
Date: Sat, 12 Dec 1998 00:00
28 lines
1940 bytes
1940 bytes
There is a possibility to determine focus without using Swing by using Component.processFocusEvent. Create a focusEvent listener for every component that looks for FOCUS_GAINED and FOCUS_LOST. When it receives FOCUS_GAINED, store the reference to the granddaddy container and the reference to the current object in a vector/hashtable/etc -- preferrable in globally accessible data storage, e.g. static class variables. And when FOCUS_LOST is received, remove the reference from this data storage. This means you can now query the data storage to find out what component currently has the focus. Franck Rasolo wrote: > I think this what you're looking for, it's taken from the Swing (1.0.3) > API documentation :- > > Class com.sun.java.swing.SwingUtilities > > public static java.awt.Component findFocusOwner(java.awt.Component c) > > Return the child component which has focus, if any. The HotJava > SecurityManager forbids applet access to getFocusOwner(), so if the > component is an applet, we check whether a JComponent has focus. > Non-Swing components in an applet on HotJava are out-of-luck, > unfortunately. > > > Is there an API that returns either awt.Component or JComponent > > to indicate it is the component that currently has focus ? > > Thanks for the info.
Technical Details
Message-ID:
<36724BF0.EE62DC90@Bigfoot.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<366F0DF0.BEA9EA48@home.com> <366F5C69.822788A4@netspin.co.uk>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,a5fd9d561ea8c109 X-Google-Attributes: gidf74b3,public From: William Yu <William_Yu@Bigfoot.com> Subject: Re: Find out which componet currently has focus Date: 1998/12/12 Message-ID: <36724BF0.EE62DC90@Bigfoot.com> X-Deja-AN: 421485707 Content-Transfer-Encoding: 7bit References: <366F0DF0.BEA9EA48@home.com> <366F5C69.822788A4@netspin.co.uk> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: Another Netscape Collabra Server User Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language