Java 如何将IDE创建的JPanel更改为自定义创建的JPanel?
我想在我的UI中更改一个特定的JPanelJava 如何将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
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) “主面板是主面板…”将该信息导入问题。这将比在评论中更引人注目。