🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: How to give focus to a component on a JDialog?

#13199
From: Edoardo Comar comar
Date: Tue, 01 Sep 1998 00:00
27 lines
1466 bytes
>I'm bringing up some JDialogs in my Swing GUI, but I haven't figured out
how
>to give the default focus to one of the components on the JDialog.
>
>For example, say there's an OK button on the JDialog.  I want it to have
>focus when the dialog comes up.

in the window activated event handler, write this code :
myJcomponent.requestFocus()

With that you can give focus also to an entry field (my frame/dialog
coordinator objects have a usually a method called prepareForInput() that
does just that).

or, for a swing Button - put this code in the dialog constructor (or in the
dialog's coordinator object) :

getRootPane().setDefaultButton(myDefaultButton);

Edo.
-------------
Edoardo Comar
<e.comar@go.nettuno.it> (home email)
<comar@tecnest.it>
PGP RSA key on keyservers  http://wwwkeys.pgp.net
key ID 29365395  created 1994/11/03
fingerprint = 5E 10 E1 46 22 35 84 3D  3F 57 E0 35 BE 5C 1E A7
Technical Details
Message-ID: <6shkoo$cfk10@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <6sfgin$9mt14@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,146ac3e38e25d8e5
X-Google-Attributes: gid111d45,public
From: "Edoardo Comar <comar@tecnest.it>" <e.comar@go.nettuno.it>
Subject: Re: How to give focus to a component on a JDialog?
Date: 1998/09/01
Message-ID: <6shkoo$cfk10@forums.borland.com>
X-Deja-AN: 386896788
References: <6sfgin$9mt14@forums.borland.com>
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.swing