在任务栏中显示JDialog无法正常工作
问题描述:
我正在使用以下代码在任务栏上显示JDialog,并且在JDK 1.6中可以正常工作.
I'm using the below code to showing JDialog on taskbar and is perfectly working in JDK 1.6.
public class test8 {
public static void main(String[] args) {
Runnable r = new Runnable() {
public void run() {
JDialog d = new JDialog((Frame)null,Dialog.ModalityType.TOOLKIT_MODAL);
d.setTitle("title");
d.setSize(300,200);
d.setVisible(true);
System.exit(0);
}
};
EventQueue.invokeLater(r);
}
}
但是当我使用该方法设置模态类型时,它不起作用
But When I'm setting the modality type using the method it's not working
public class test8 {
public static void main(String[] args) {
Runnable r = new Runnable() {
public void run() {
JDialog d = new JDialog();
d.setTitle("title");
d.setSize(300,200);
d.setModalityType(Dialog.ModalityType.TOOLKIT_MODAL);
d.setVisible(true);
System.exit(0);
}
};
EventQueue.invokeLater(r);
}
}
两个代码之间有什么区别?有什么方法可以解决这个问题吗?
What is the difference betwwen the two codes ? Is there any way to solve this using the method ?
答
问题是,如果JDialog
的某些构造函数出于历史原因是所有者null
,则它们会创建一个虚拟框架所有者.但是Dialog
一定没有所有者,就像顶级窗口一样可见.即
The problem is that certain constructors of JDialog
create a dummy frame owner if the owner is null
for historical reasons. But a Dialog
must not have an owner to be visible like a top-level window. I.e.
JDialog d=new JDialog((Window)null);
d.setModalityType(ModalityType.TOOLKIT_MODAL);
d.setVisible(true);
将起作用.