【问题标题】:Closing JAppletFrame without closing JFrame关闭 JApplet jFrame 而不关闭 JFrame
【发布时间】:2015-04-11 16:33:29
【问题描述】:

我在我的父 JFrame 上放置了一个按钮,单击它会打开一个 JAppletFrame,现在当我关闭 JAppletFrame 时,整个应用程序都会关闭。那么有什么方法只关闭我的子框架而不关闭父框架吗?这里是代码

public static void main(String[] args) {

    applet = new HearDAHDSR();


    //User defined class containing the frames
    window = new window1();
    //window2 window = new window2();
    //then you set to your node
    frame = window.frame();
    frame.setSize(700, 500);
    frame.setVisible(true);

    //User defined class containing all panels
    panel = new Panels();

    StringBuilder b = new StringBuilder();

    //Retrieving the width and height of the frame
    w = frame.getContentPane().getWidth();
    h = frame.getContentPane().getHeight();

    //
    JPanel bar_panel = panel.Bar();
    JPanel tabbed_playlist = panel.Playlist(w,h);

    frame.getContentPane().add(bar_panel, BorderLayout.NORTH);

    JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    frame.getContentPane().add(tabbedPane, BorderLayout.CENTER);

    //Adding the Playlist and Library tabs
    tabbedPane.addTab("Playlist", tabbed_playlist);
    tabbedPane.addTab("Library", panel.Library(w,h));

    launch(args);;
}


}
public static void effect2(){
    frame2 = new JAppletFrame( "Effect", applet );
    frame2.setSize( 440, 300 );
    frame2.setVisible( true );
    frame2.test();
    frame2.setDefaultCloseOperation(frame2.EXIT_ON_CLOSE);

}

【问题讨论】:

    标签: java swing javafx


    【解决方案1】:
    frame2.setDefaultCloseOperation(frame2.EXIT_ON_CLOSE);
    

    不要使用EXIT_ON_CLOSE。而是使用:

    frame2.setDefaultCloseOperation(frame2.DISPOSE_ON_CLOSE);
    

    如果 applet 框架是唯一的框架,则 JVM 将退出,但如果打开了多个框架,则另一个框架将保持打开状态。

    【讨论】:

    • 是的,也试过了,但没用……甚至试过 HIDE_ON_CLOSE 但没有运气
    • 尝试发布 MCVE 并包含 JAppletFrame 代码或至少链接到 Java 文档。我从没听说过那门课..
    猜你喜欢
    • 1970-01-01
    • 2010-12-29
    • 2021-04-17
    • 1970-01-01
    • 1970-01-01
    • 2012-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多