Article View: borland.public.jbuilder.java.swing
Article #789Action performed event handler fires twice
From: BrianW
Date: Fri, 25 Jun 2004 11:58
Date: Fri, 25 Jun 2004 11:58
61 lines
2058 bytes
2058 bytes
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
Technical Details
Message-ID:
<2k2icaF16gj6pU1@uni-berlin.de>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,11c992ff0658e7ea,start X-Google-Attributes: gid111d45,public 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: Action performed event handler fires twice Date: Fri, 25 Jun 2004 12:58:48 +0100 Lines: 65 Message-ID: <2k2icaF16gj6pU1@uni-berlin.de> X-Trace: news.uni-berlin.de zp/NWjEcRg6Mv53yH8wy4QrDqYVtytN1m1Wf4fAuzn+7EWubcU 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