如何使模态 JDialog 在显示后立即执行代码

发布于 2024-10-09 19:50:10 字数 186 浏览 0 评论 0原文

好的,我有一个对象列表。我需要显示一个 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.

Thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

倾城月光淡如水﹏ 2024-10-16 19:50:10
JDialog dialog = new JDialog(...);
...
dialog.addComponentListener(new ComponentAdapter()
{
    public void componentShown(ComponentEvent e)
    {
        System.out.println("Time to do something");
    }
});
dialog.setVisible( true );
JDialog dialog = new JDialog(...);
...
dialog.addComponentListener(new ComponentAdapter()
{
    public void componentShown(ComponentEvent e)
    {
        System.out.println("Time to do something");
    }
});
dialog.setVisible( true );
迎风吟唱 2024-10-16 19:50:10
JDialog dialog = new JDialog(...);
dialog.addWindowListener(new WindowAdaper() {
    @Override
    public void windowOpened(WindowEvent e) {
        super.windowOpened(e);
        // do something
    }
});

你明白了。

JDialog dialog = new JDialog(...);
dialog.addWindowListener(new WindowAdaper() {
    @Override
    public void windowOpened(WindowEvent e) {
        super.windowOpened(e);
        // do something
    }
});

You get the idea.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文