is there any way call other JinternalFrame from an JinternalFrame but, in the desktopPane of of main Jframe.

半城伤御伤魂 提交于 2019-12-06 13:44:34

I found the solution .

for the first class(MainApplication) where your Jframe and JDesktopPane inside place code below

public javax.swing.JDesktopPane getDesktopPane() {
    return desktopPane;
}

then use in any JinternalFrame class file like this to call another one(YourJinternalFrame)

 YourJinternalFrame  nw = YourJinternalFrame.getInstance();
    nw.pack();
    if (nw.isVisible()) {
    } else {
        getDesktopPane().add(nw);
        nw.setVisible(true);
    }
    try {
        nw.setMaximum(true);
    } catch (PropertyVetoException ex) {
        Logger.getLogger(MainApplication.class.getName()).log(Level.SEVERE, null, ex);
    }

to get only one instance of called JinternalFrame place this code below in the called JinternalFrame(YourJinternalFrame)

private static YourJinternalFrame myInstance;

public static YourJinternalFrame getInstance() {
    if (myInstance == null) {
        myInstance = new YourJinternalFrame();
    }
    return myInstance;

Thank me:)

First create f1 frame object on f2 button action

F1 f1 = new F1();

Then create a JDesktopPane object like this

JDesktopPane desktopPane = getDesktopPane();
desktopPane.add(f1);//add f1 to desktop pane
f1.setVisible(true);// set the f1 frame visible

Finally if needed dispose the current frame

this.dispose();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!