Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将IDE创建的JPanel更改为自定义创建的JPanel?_Java_Swing_Intellij Idea_Jpanel - Fatal编程技术网

Java 如何将IDE创建的JPanel更改为自定义创建的JPanel?

Java 如何将IDE创建的JPanel更改为自定义创建的JPanel?,java,swing,intellij-idea,jpanel,Java,Swing,Intellij Idea,Jpanel,我想在我的UI中更改一个特定的JPanel public Tester() { this.setSize(800,800); this.setContentPane(mainPanel); // A created panel using Intellij IDE otherPanel = new MyPanel(); // A custom created panel without the use of Intellij changePanelButton.a

我想在我的UI中更改一个特定的JPanel

public Tester() {
    this.setSize(800,800);
    this.setContentPane(mainPanel); // A created panel using Intellij IDE
    otherPanel = new MyPanel(); // A custom created panel without the use of Intellij
    changePanelButton.addActionListener(e -> {
        changePanel = otherPanel // Not Working
    });
}

我无法使用JFrame中的setContentPane,因为它将更改框架的所有内容,而不仅仅是我要更改的面板。

mainPanel是我框架的主面板,它由一个面板和一个按钮(位于面板外部)组成。changePanel是我要更改的面板的当前名称。otherPanel是一个实例化的JPanel对象,它调用MyPanel(),MyPanel()是自定义创建的面板。1)如中所示使用。2) 为了更快地获得更好的帮助,请添加或。3) “主面板是主面板…”将该信息导入问题。这将比在评论中更引人注目。