🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Action performed event handler fires twice

#791
From: BrianW
Date: Fri, 25 Jun 2004 20:22
76 lines
2560 bytes
"BrianW" <brian@nospam.net> wrote in message
news:2k2icaF16gj6pU1@uni-berlin.de...
> Hi,
>
> I have a JComboBox event handler which reads a file corresponding to the
> selection, using BufferedReader, then populates a JTextArea with the file
> contents. This is the code I'm concerned about:
>
> void showManifestFile(String filename) throws IOException {
>
> // Populate the list box with the contents of the specified file
>
>   String inputLine;
>
>   try {
>
>     inStream = new BufferedReader(new FileReader(filename));
>
>   } catch (FileNotFoundException e) {
>
>     inStream.close();
>
>   showMessageBox("Unable to open " + filename + " on local machine.",
true);
>
> }
>
> while (true) {
>
>   inputLine = inStream.readLine();
>
>   if (inputLine == null) break;
>
>   if (inputLine.length() == 0) continue;
>
>   jManifestInfoTextArea.append(inputLine + "\n");
>
> }
>
> inStream.close();
>
> } // showManifestFile
>
>
>
> The problem is that the event handler is being called twice, so the text
> ends up in the text area twice. I read somewhere that it may be because
the
> event handler doesn't register completion until the input stream has
closed,
> so that the next time it checks for events, it hasn't been satisfied yet
and
> gets fired again.
>
>
>
> Is this true? I have other combo boxes with very similar code, except that
a
> BufferedReader is not involved, and the action performed events only fire
> once, as expected.
>
>
>
> Any suggestions please?
>
>
>
> Brian

I wondered if it was because I was running it in debug mode, but it still
does it in release mode. However I have implemented the obvious workaround -
toggle a boolean and return without doing anything if it is false. There has
to be a better solution though!

Brian
Technical Details
Message-ID: <2k3ft8F17fcfeU1@uni-berlin.de>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail
References: <2k2icaF16gj6pU1@uni-berlin.de>

Show Full Headers
Complete Article Headers
X-Google-Thread: 111d45,11c992ff0658e7ea
X-Google-Attributes: gid111d45,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail
From: "BrianW" <brian@nospam.net>
Newsgroups: borland.public.jbuilder.java.swing
Subject: Re: Action performed event handler fires twice
Date: Fri, 25 Jun 2004 21:22:47 +0100
Lines: 78
Message-ID: <2k3ft8F17fcfeU1@uni-berlin.de>
References: <2k2icaF16gj6pU1@uni-berlin.de>
X-Trace: news.uni-berlin.de ahC4Lf5bwMa1truguBKKoAMVL9y6IXrpvgnh9mMV6iO8SqnQTd
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409