🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: JFrame Default focus Problem

#12624
From: Petr Srajer
Date: Thu, 03 Dec 1998 00:00
31 lines
2115 bytes
Max Polk wrote:

> In article <3650BACC.5365258@ultranet.com>, apogee08@ultranet.com says...
> > I have a JFrame with a couple of JTextField's on it. I want a particular
> > JTextField to have focus, a flashing caret and be ready for user input
> > the moment it becomes visible. I can get it to have focus and a flashing
> > caret, but the user must always click in the control or tab out and back
> > into it to be able to actually begin entering text.
> >
> > I've tried getDefaultFocus(), grabFocus(), requestFocus() and I've even
> > created my own Focus and MouseEvents and done a dispatchEvent...nothing
> > seems to work. This is using Swing 1.0.3, the problem seems even worse
> > with Swing 1.0.1. Any help would be greatly appreciated.
>
> The problem in most cases is solved by adding a focus listener to *THE
> RIGHT COMPONENTS* and when the component gets focus (typically a frame or
> window or panel), set the focus to the desired component within it.
>
> The trick is not programmatically calling requestFocus when the component
> is created, but rather, *WAIT* until a focus event occurs, which can be
> much, much later in time when the GUI is finally pretty far along
> painting, and when you get it, *THAT* is the time to set the focus on
> your desired component.
>
> Also make sure to never break the "single thread rule".  See the swing
> connection on java.sun.com for more information about why Swing is *NOT*
> thread safe.

Thank you, it's work perfectly.(Listener on window)

        Petr Srajer.
Technical Details
Message-ID: <36664851.EE38B3FC@ais.cz>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <3650BACC.5365258@ultranet.com> <MPG.10ba70427f8c380a9896bd@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,9878af0d635aaa30
X-Google-Attributes: gid111d45,public
From: Petr Srajer <Petr.Srajer@ais.cz>
Subject: Re: JFrame Default focus Problem
Date: 1998/12/03
Message-ID: <36664851.EE38B3FC@ais.cz>
X-Deja-AN: 418148908
Content-Transfer-Encoding: 7bit
References: <3650BACC.5365258@ultranet.com> <MPG.10ba70427f8c380a9896bd@forums.borland.com>
Content-Type: text/plain; charset=us-ascii
Organization: AIS Software s.r.o.
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing