在任务栏中显示JDialog无法正常工作 [英] Showing JDialog in taskbar not working

查看:54
本文介绍了在任务栏中显示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);

将起作用.

这篇关于在任务栏中显示JDialog无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆