Article View: borland.public.jbuilder.java.language
Article #19640Re: Initializing dialog...
From: Greg Hamer
Date: Sun, 18 Jan 1998 00:00
Date: Sun, 18 Jan 1998 00:00
42 lines
2022 bytes
2022 bytes
The way I do it is to call enableEvents(AWTEvent.WINDOW_EVENT_MASK) in
the dialogs constructor and then override processWindowEvent:
boolean firstTime = false;
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID()== WindowEvent.WINDOW_ACTIVATED && ! firstTime) {
firstTextField.requestFocus();
firstTime = true;
}
To get <Enter> to invoke a button, you can add a keyListener to all the
components that makes sense( enter in a TextArea should not invoke a
button) and call the method that
gets invoked when the default button is clicked if you detect
KeyEvent.VK_ENTER.
Dhruva Reddy wrote:
> I have a dialog with a column of text fields, the first of which I
> would like to have gain focus. I tried overriding setVisible() with a
> call to TextField.requestFocus(), but Dialog.setVisible() does not
> return until after the dialog is gone. requestFocus() requires that
> the component is visible to work.
>
> Does somebody know of a way to do this?
>
> Also, does someone know how to make the OK button on a dialog the
> default button, that is, you hit <Enter> and it's just like clicking
> OK.
>
> Thanks,
> Dhruva
>
> --
> -----------------------------------------------------------
> Dhruva B. Reddy mailto:dreddy@cgi.com
> Carnegie Group, Inc. 707 17th Street, Suite 2100
> (303) 295 0366 x336 Denver, CO 80202, USA
> -----------------------------------------------------------
>
Technical Details
Message-ID:
<34C297F2.70572D2@borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<34B57E5D.3BAD2F27@cgi.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,122f50da3a6aaa02,start X-Google-Attributes: gidf74b3,public From: Greg Hamer <ghamer@borland.com> Subject: Re: Initializing dialog... Date: 1998/01/18 Message-ID: <34C297F2.70572D2@borland.com> X-Deja-AN: 317196079 Content-Transfer-Encoding: 7bit References: <34B57E5D.3BAD2F27@cgi.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Organization: None Newsgroups: borland.public.jbuilder.java.language