繁体   English   中英

当父JFrame出现时,为什么这个无模式的子JDialog最小化?

[英]Why isn't this modeless child JDialog minimized when parent JFrame is?

我的理解是,当父JFrame被最小化时,其子项也被最小化,但在下面的简单示例中它不会发生(即,当jframe最小化时,子对话保持可见)。 我错过了什么吗?

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();
            }
        } );
    }
}

谢谢!

尝试获取Window []并将它们全部关闭......也许这适用于每个操作系统。

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();
            }
        }
    } );

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM