3

My understanding is that when a parent JFrame is minimized then its children also are minimized but in the following dirt-simple example it doesn't happen (i.e. the child dialog stays visible when the jframe is minimized). Am I missing something?

public class Test
{
    private JFrame f1;
    private JDialog d2;

    private void createAndShowGUI()
    {
        f1 = new JFrame("(parent frame)");
        f1.addWindowListener( new WindowAdapter()
        {
            public void windowClosing( WindowEvent e )
            {
                e.getWindow().dispose();
            }
        } );
        f1.setBounds(32, 32, 300, 200);
        d2 = new JDialog(f1, "child dialog" );
        d2.setBounds(100, 100, 300, 200);
        d2.setVisible( true );
        f1.setVisible( true );
    }

    public static void main( String[] args )
    {
        // Schedule a job for the event-dispatching thread:
        // creating and showing this application's GUI.
        SwingUtilities.invokeLater( new Runnable()
        {
            public void run()
            {
                Test test = new Test();
                test.createAndShowGUI();
            }
        } );
    }
}

Thanks!

DeegC
  • 373
  • 4
  • 12

1 Answers1

0

Try getting Window[] and close them all... Maybe that works in every OS.

private void createAndShowGUI() {
    f1 = new JFrame("(parent frame)");
    f1.addWindowListener( new WindowAdapter() {
        public void windowClosing( WindowEvent e ) {
            Window[] windows = e.getWindow().getOwnedWindows();
            for (Window window : windows) {
                window.dispose();
            }
        }
    } );
Leolian
  • 181
  • 1
  • 1
  • 8