如何使模态JDialog在显示后立即执行代码 [英] How to make a modal JDialog execute code immediately upon being shown

查看:47
本文介绍了如何使模态JDialog在显示后立即执行代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我有一个对象列表.我需要显示一个Modal JDialog,然后将其传递给对象列表并使其作用于它们.问题是,当我调用.show()时,它劫持了EDT.理想的情况是能够将列表传递给构造函数,然后在显示对话框时执行有问题的函数.在C#中,我将为此使用Loaded事件,但是如何执行JDialog使我逃脱了.

Ok, I have a list of objects. I need to show a Modal JDialog and then pass it this list of objects and have it act on them. The problem is that when I call .show() it hijacks the EDT. The ideal situation would be to be able to pass the list in to the constructor and then when the dialog is shown, execute the function in question. In C# I'd use the Loaded event for this, but how to do it a JDialog escapes me.

有想法吗?

推荐答案

JDialog dialog = new JDialog(...);
...
dialog.addComponentListener(new ComponentAdapter()
{
    public void componentShown(ComponentEvent e)
    {
        System.out.println("Time to do something");
    }
});
dialog.setVisible( true );

这篇关于如何使模态JDialog在显示后立即执行代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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