首页 > 解决方案 > 如何将 IDE 创建的 JPanel 更改为自定义创建的 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.addActionListener(e -> {
        changePanel = otherPanel // Not Working
    });
}

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

标签: javaswingintellij-ideajpanel

解决方案


推荐阅读