Article View: borland.public.jbuilder.java.api
Article #1716Re: repeating the showMessageDialog
From: Torsten Welches
Date: Mon, 15 Oct 2001 11:00
Date: Mon, 15 Oct 2001 11:00
38 lines
2195 bytes
2195 bytes
"Ant๏ฟฝnio Ferreira" <antonio.ferreira@artesis.co.pt> wrote:
> public void focusLost(FocusEvent e) {
> int k;
>
> try {
> k = Integer.parseInt(jTextField1.getText());
> if (k < 1) {
> JOptionPane.showMessageDialog(null,
> "You must enter a value greater than zero",
> "Atention",
> JOptionPane.WARNING_MESSAGE);
> jTextField1.requestFocus();
> }
> }catch (NumberFormatException excp) {
> System.out.println(excp.getMessage());
> JOptionPane.showMessageDialog(null,
> "You must enter a numeric value.",
> "Atention",
> JOptionPane.WARNING_MESSAGE);
> jTextField1.requestFocus();
> }
> }
> });
>
> It always executes twice the appropiate showMessageDialog.
> Can anyone explain this strange behavior.
upon leaving your text field you get a FOCUS_LOST event.
In case your validation fails you pop up a modal dialog and
reset the focus - that triggers a FOCUS_GAINED with the same
validation ...
you might want to look into javax.swing.InputVerifier and
JComponent.setInputVerifier instead.
Torsten
Technical Details
Message-ID:
<3bcac1ca$1_2@dnews>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!news-peer-west.sprintlink.net!news.sprintlink.net!enews.sgi.com!news.xtra.co.nz!newsfeeds.ihug.co.nz!ihug.co.nz!dnewsReferences:
<3bcab15a_2@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: 1089d0,ca11cf111dc9b441 X-Google-Attributes: gid1089d0,public X-Google-ArrivalTime: 2001-10-15 04:03:29 PST From: "Torsten Welches" <torsten.welches@who.cares.netcologne.de> Sender: "Torsten Welches" <torsten.welches@who.cares.netcologne.de> Reply-To: "Torsten Welches" <torsten.welches@who.cares.netcologne.de> Subject: Re: repeating the showMessageDialog Newsgroups: borland.public.jbuilder.java.api X-User-Info: 193.158.55.74 193.158.55.74 References: <3bcab15a_2@dnews> NNTP-Posting-Host: 207.105.83.65 Message-ID: <3bcac1ca$1_2@dnews> Date: 15 Oct 2001 04:00:26 -0700 X-Trace: dnews 1003143626 207.105.83.65 (15 Oct 2001 04:00:26 -0700) Lines: 39 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!news-peer-west.sprintlink.net!news.sprintlink.net!enews.sgi.com!news.xtra.co.nz!newsfeeds.ihug.co.nz!ihug.co.nz!dnews