Article View: borland.public.jbuilder.java.swing
Article #47Problem with focusLost event... PLEASE HELP !!
From: Nadia AKROUR
Date: Wed, 17 Nov 1999 00:00
Date: Wed, 17 Nov 1999 00:00
76 lines
2483 bytes
2483 bytes
Hello,
The problem is the following :
I have a JWindow containing only a JTable. And I want the window to
close on table focusLost() event.
The window is showing by a clic on a button.
Here is the code :
...
JButton myBut = new JButton("show the window");
myBut.addActionListener( new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
onShowWindow(e);
}
});
...
public void onShowWindow(ActionEvent e) {
MyWindow mywin = new MyWindow();
mywin.show();
mywin.requestFocus();
}
...
public class MyWindow extends JWindow {
MyTable mytab = new MyTable();
public MyWindow() {
getContentPane().setLayout(new BorderLayout());
getContentPane().setBackground(Color.white);
getContentPane().add(mytab,BorderLayout.CENTER);
mytab.addFocusListener( new FocusAdapter() {
public void focusGained(FocusEvent e) {
System.out.println("tab focusGained");
}
public void focusLost(FocusEvent e) {
System.out.println("tab focusLost");
close();
}
});
addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent e) {
mytab.requestFocus();
System.out.println("window focusGained");
}
public void focusLost(FocusEvent e) {
System.out.println("window focusLost");
}
});
}
public void close() {
// get the selection in the table
...
// close the window
dispose();
}
}
the output is :
window focusGained
tab focusLost
close()
But the window pops up and closes itself immediatly.
Please tell me if I am doing something wrong...
Any help would be very appreciated becos I'm going to loose my mind soon
!!
--
Nadia.
Technical Details
Message-ID:
<3832DC26.93786C08@spring.fr>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,a0662ecd0a1aac05,start X-Google-Attributes: gid111d45,public X-Google-Thread: f74b3,a0662ecd0a1aac05,start X-Google-Attributes: gidf74b3,public From: Nadia AKROUR <nakrour@spring.fr> Subject: Problem with focusLost event... PLEASE HELP !! Date: 1999/11/17 Message-ID: <3832DC26.93786C08@spring.fr> X-Deja-AN: 549738086 Content-Transfer-Encoding: 7bit Organization: SPRING TECHNOLOGIES X-Accept-Language: fr-FR,en Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing,borland.public.jbuilder.java.language