Article View: borland.public.jbuilder.java.swing
Article #7759Re: focusLost & JTextField
From: Tulan
Date: Thu, 14 Dec 2000 15:30
Date: Thu, 14 Dec 2000 15:30
32 lines
2336 bytes
2336 bytes
John McGrath [TeamB] <ng-b@JPMcGrath.net> wrote:
>I presume that you see the dialog twice
You are correct that the focusLost was called twice; however, I don't know why it was called twice because most java code were generated. I would like to learn the correct way to do this. I use the design tab to create my screen two TextFields and one TextArea, then add the focusLost event for the two TextFields. The focusLost function has a very simple test:
void jTF_src_focusLost(FocusEvent e) {
JTextField src = (JTextField) e.getSource();
if (src.getText().length () == 0) {
// I cannot put the showMessageDialog here, because it will
// pop up forever.
setFocus(src);
return;
}
File f = new File(src.getText());
if (f.canRead()) {
return;
} else {
JOptionPane.showMessageDialog(ArchUIFrame.this, "Source file [" + src.getText() + "] is not readable or does not exist.",
"Error", JOptionPane.ERROR_MESSAGE);
// if I removed the src.setText(""), then the dialog box pops
// forever.
src.setText("");
// if I only have the src.requestFocus(), then the cursor will
// not stay in this field.
Runnable r = new Runnable() {
public void run() { jTF_src.requestFocus(); }
};
SwingUtilities.invokeLater(r);
return;
}
}
I steped through the code, and it showed me the following code sequences: TextField1.focusLost -> processWindowEvent -> TextField1.focusLost.
Technical Details
Message-ID:
<3a38e79d$1_1@dnews>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!nntp-relay.ihug.net!ihug.co.nz!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!neel.uni2.net!newssuck.uni2.dk!bornews.borland.com!dnews!207.105.83.65References:
<3a37f0a7_2@dnews> <MPG.14a24bebe19abe01989dbd@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,d6ed4023ba0d7fb6 X-Google-Attributes: gid111d45,public X-Google-ArrivalTime: 2000-12-14 07:35:49 PST From: "Tulan" <twhu@lucent.com> Sender: "Tulan" <twhu@lucent.com> Reply-To: "Tulan" <twhu@lucent.com> Subject: Re: focusLost & JTextField Newsgroups: borland.public.jbuilder.java.swing X-User-Info: 192.11.223.102 192.11.223.102 References: <3a37f0a7_2@dnews> <MPG.14a24bebe19abe01989dbd@forums.borland.com> NNTP-Posting-Host: 207.105.83.65 Message-ID: <3a38e79d$1_1@dnews> Date: 14 Dec 2000 07:30:37 -0800 X-Trace: 14 Dec 2000 07:30:37 -0800, 207.105.83.65 Lines: 32 Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!nntp-relay.ihug.net!ihug.co.nz!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!neel.uni2.net!newssuck.uni2.dk!bornews.borland.com!dnews!207.105.83.65