How to make JDialog modal code right after showing

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

Thoughts?

+3
source share
2 answers
JDialog dialog = new JDialog(...);
...
dialog.addComponentListener(new ComponentAdapter()
{
    public void componentShown(ComponentEvent e)
    {
        System.out.println("Time to do something");
    }
});
dialog.setVisible( true );
+4
source
JDialog dialog = new JDialog(...);
dialog.addWindowListener(new WindowAdaper() {
    @Override
    public void windowOpened(WindowEvent e) {
        super.windowOpened(e);
        // do something
    }
});

You get the idea.

+1
source

Source: https://habr.com/ru/post/1782372/


All Articles