Article View: borland.public.jbuilder.java.swing
Article #8033Re: How to set the focus on a control ?
From: Larry Gensch
Date: Mon, 13 Nov 2000 00:00
Date: Mon, 13 Nov 2000 00:00
31 lines
2009 bytes
2009 bytes
In article <3A0952C7.605063AD@bluewin.ch>,
Thomas Bednarz <tkmb@bluewin.ch> writes:
> How can I set the focus on a control?
> ...
> MyCombo.requestFocus();
> MyCombo.requestDefaultFocus();
>
> Do I need to call something else after calling one of the above
> functions? Users are about to kill me, because they always have to hit
> the tab key before they can start their selection in the combobox.
Somewhere within Swing, the focus manager forces what it considers the
first component to have the focus, which means that your
requestFocus() calls are being ignored.
The solution that I have found is to invoke a Swing Worker thread to
set the focus, which will usually occur AFTER the focus manager sets
the focus:
SwingUtilities.invokeLater(new Runnable() {
public void run() {
myCombo.requestFocus();
}
});
--
Larry Gensch Larry.Gensch@compaq.com
Compaq Computer Corporation As usual, the standard
110 Spit Brook Road ZKO3-2/W17 disclaimers apply, etc.
Nashua, NH 03062 Yada yada yada
Technical Details
Message-ID:
<8up244$7bl$2@mailint03.im.hou.compaq.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<3A0952C7.605063AD@bluewin.ch>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,e40a22670d2d438d X-Google-Attributes: gid111d45,public X-Google-Thread: 10fd6d,e40a22670d2d438d X-Google-Attributes: gid10fd6d,public From: lar3ry@zk3.dec.com (Larry Gensch) Subject: Re: How to set the focus on a control ? Date: 2000/11/13 Message-ID: <8up244$7bl$2@mailint03.im.hou.compaq.com> X-Deja-AN: 693099411 References: <3A0952C7.605063AD@bluewin.ch> Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@mailint03.im.hou.compaq.com X-Trace: mailint03.im.hou.compaq.com 974130116 7541 16.141.0.174 (13 Nov 2000 15:41:56 GMT) Organization: Compaq Computer Corporation Mime-Version: 1.0 Reply-To: larry.gensch@compaq.com NNTP-Posting-Date: 13 Nov 2000 15:41:56 GMT Newsgroups: borland.public.jbuilder.java.swing,comp.lang.java.gui