当前位置: 技术问答>java相关
关闭Jdialog连主窗口也关了?
来源: 互联网 发布时间:2015-05-23
本文导语: 在主窗口下,我调出一个Jdialog,按确定或是取消后,Jdialog是关闭了,我是执行dispose()的,但这个过程把主窗口也一同关闭了,请问这通常是由于哪些情况导致的呢? dialog.addWindowListener(new WindowAdapter() ...
在主窗口下,我调出一个Jdialog,按确定或是取消后,Jdialog是关闭了,我是执行dispose()的,但这个过程把主窗口也一同关闭了,请问这通常是由于哪些情况导致的呢?
dialog.addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent dialoge) {
dispose();
}
});
dialog.addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent dialoge) {
dispose();
}
});
|
dialog.addWindowListener在那个类里面dispose就会把那个类关掉,因为这个相当于this.dispose();,估计你把这个放在上级frame的类里面了,所以把它关掉了。你应该设法调用dialog.dispose();
|
dialog.addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent dialoge)
{
dispose();
}
});
改为:
dialog.addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent dialoge)
{
dialogClose(dialoge);
}
});
private dialogClose(WindowEvent dialoge)
{
dialog.dispose();
}
{ public void windowClosing(WindowEvent dialoge)
{
dispose();
}
});
改为:
dialog.addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent dialoge)
{
dialogClose(dialoge);
}
});
private dialogClose(WindowEvent dialoge)
{
dialog.dispose();
}
|
你相当于执行了
dialog.addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEventdialoge)
{this.dispose();}
});
dispose是发给主窗口的。你的dialog能关,主要是因为主窗口关了才引起的。
所以解决方法是将dispose信息发到dialog。
dialog.addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEventdialoge)
{dialog.dispose();}
});
dialog.addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEventdialoge)
{this.dispose();}
});
dispose是发给主窗口的。你的dialog能关,主要是因为主窗口关了才引起的。
所以解决方法是将dispose信息发到dialog。
dialog.addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEventdialoge)
{dialog.dispose();}
});
|
我想不是这样吧,你应该反dispose();改成this.dispose();这样才对;