JDialog.isVisible() Not Executing on Event Dispatch Thread When it Should Be?

55 views Asked by At

I am building a JDialog on the EDT. As soon as I call pack() the JDialog's isVisible method is called several times. The first time it's called SwingUtilities.isEventDispatchThread() returns false. Why is that? Sample program follows.

public class EDTTest extends JDialog
{
    public static void main(String[] args)
    {
        SwingUtilities.invokeLater( () -> {
            EDTTest  dialog  = new EDTTest();
            dialog.buildGUI();
        });
    }
    
    private void buildGUI()
    {
        JButton button  = new JButton( "Exit" );
        JPanel  panel   = new JPanel();
        
        button.addActionListener( e -> System.exit( 0 ) );
        panel.add( button );
        setContentPane( panel );
        System.out.println( "Packing" );
        pack();
        setVisible( true );
    }
    
    @Override
    public boolean isVisible()
    {
        System.out.println( SwingUtilities.isEventDispatchThread() );
        boolean isVis   = super.isVisible();
        return isVis;
    }
}
0

There are 0 answers