🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Where is focus?

#13126
From: Vasudevan Srinivasan
Date: Fri, 25 Sep 1998 00:00
56 lines
2516 bytes
Hi,
How/When does requestFocus() work?
I tried the following bit of code:

 try {
     value = jtxtValue.getText();
     Integer tempInt = new Integer(value);
  } catch (NumberFormatException nfe) {
    JOptionPane msgBox = new JOptionPane();
    msgBox.showMessageDialog(this, "Invalid value", "Validation Error",
msgBox.ERROR_MESSAGE);
    jtxtValue.requestFocus();
  }
the above code is part of an applet.
this produces different results under diff circumstances:
1. when i run applet1.java under IDE, after the jtxtValue.requestFocus() is
executed, the focus is set on
JBuilder IDE.
2. when i minimize IDE, and run applet1.java after the requestFocus(), the
focus is apparently lost, ie
atleast it is not on my app.
3. when i run package.applet1.html, the first time when this code executes
the focus is lost; the second time
this code executes, it brings up the IDE (even though its minimized).

when i removed the requestFocus(), all of the above hold true. basically, the
app is unaffected.
im running jbuilder2 and swing1.0.1. is this a bug or i need somethingmore to
do?

a related question is how does swing manipulate z-order of windows. can
anyone refer any doc on this.
thanks
Vasu

Paul Furbacher wrote:

> Guy Scharf wrote:
> >
> > I have created a JDialog with three JButtons and two JLabels on it.
> > This is a simple dialog to ask the user to make a choice.
> >
> > When the dialog is displayed, where is the focus?  If I press the Tab
> > key, focus moves to the first button.  But I would prefer that it be on
> > the first button to begin with.  How do I make that happen?
> >
> > I am running JBuilder 2 and Swing 1.0.3.
>
> Take a look at how JOptionPane does it -- notably the
> calls to "setInitialValue()" and "selectInitialValue()"
> in "showOptionDialog()".
>
> Or you could try a "requestFocus()", but that supposedly
> doesn't work until the component is visible.
>
> Paul Furbacher
Technical Details
Message-ID: <360BB18A.1D99BEED@netrisk.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <360AB611.1D3BB742@swarc.com> <360B0D63.A905B78A@bilbo.bio.purdue.edu>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,1f6f9d6585b5c186
X-Google-Attributes: gid111d45,public
From: Vasudevan Srinivasan <vasudevan@netrisk.com>
Subject: Re: Where is focus?
Date: 1998/09/25
Message-ID: <360BB18A.1D99BEED@netrisk.com>
X-Deja-AN: 394748574
Content-Transfer-Encoding: 7bit
References: <360AB611.1D3BB742@swarc.com> <360B0D63.A905B78A@bilbo.bio.purdue.edu>
Content-Type: text/plain; charset=us-ascii
Organization: NetRisk Inc.
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing