gpt4 book ai didi

java - 在单个 jframe 上交换两个不同的分割面板

转载 作者:行者123 更新时间:2023-12-01 12:52:39 25 4
gpt4 key购买 nike

拜托各位,我有两个分割 Pane ,比如说 Pane A 和 Pane B,我在 Pane A 上放置了一个按钮,这样如果单击该按钮, Pane A 就会隐藏, Pane B 就会变得可见,但每次我尝试这样做时我收到一个错误,上面写着:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Do not use this method  
at net.java.dev.designgridlayout.DesignGridLayoutManager.removeLayoutComponent(DesignGridLayoutManager.java:122).

最佳答案

描述不足以给出深刻的答案。但基于documentation of the method that causes the error ,似乎根本不支持从这样的布局中删除组件。

您可以使用不同的布局管理器。也许是CardLayout可能会有帮助。如有疑问,应该总是可以引入额外的容器。我将尝试在这里勾勒出这个想法,尽管没有人知道您的代码是什么样的:

class GUI {
private JPanel containerA = new JPanel(new GridLayout(1,1));

void init() {
...
// Here "grid" is the component that has the DesignGridLayout:
grid.add(containerA);
containerA.add(splitPaneA);
}

void whenTheButtonIsClicked() {
containerA.removeAll();
containerA.add(splitPaneB);
containerA.revalidate();
}
}

关于java - 在单个 jframe 上交换两个不同的分割面板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24107027/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com