gpt4 book ai didi

java - GridBagLayout 一半组件不可见

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

我正在尝试创建一个 3 x 4 的 jpanels 网格。 2 by 4 is doable with gridLayout but i cannot add the cyan jpanel along the bottom. This is What I am getting when I use GridBagLayout.
下面是我的网格包约束,我不知道为什么,但面板 4-8 是不可见的

     ///////////Build Top Panels///////////
buildPanel();
gc.weightx = 0.5;
gc.gridx = 0;
gc.gridy = 0;
this.add(p1,gc); // panel1

buildPanel2();
gc.gridx = 1;
gc.gridy = 0;
this.add(p2,gc); //panel2

buildPanel3();
gc.gridx = 2;
gc.gridy = 0;
this.add(p3,gc);//panel3

buildPanel4();
gc.gridx = 3;
gc.gridy = 0;
this.add(p4,gc);//panel4

buildBottomPanel();
gc.gridx = 0;
gc.gridy = 2;
this.add(b1,gc);//panel5

buildBottomPanel2();
gc.gridx = 1;
gc.gridy = 2;
this.add(b2,gc);//panel6

buildBottomPanel3();
gc.gridx = 2;
gc.gridy = 2;
this.add(b3,gc);//panel7

buildBottomPanel4();
gc.gridx = 3;
gc.gridy = 2;
this.add(b4,gc);//panel8

buildFooter();
gc.gridx = 0;
gc.gridy = 2;
gc.gridwidth = 4;
gc.fill = GridBagConstraints.HORIZONTAL;
this.add(footer,gc);//panel9

最佳答案

buildBottomPanel() 到 buildBottomPanel4() 放置在 (0, 2) 到 (3,2)

gc.gridx = 0;
gc.gridy = 2;
this.add(b1,gc);//panel5

gc.gridx = 3;
gc.gridy = 2;
this.add(b4,gc);//panel8

然后你的页脚被放置在它们的上面:

buildFooter();
gc.gridx = 0;
gc.gridy = 2;
gc.gridwidth = 4;
gc.fill = GridBagConstraints.HORIZONTAL;
this.add(footer,gc);//panel9

使用gc.gridy = 1作为底部面板。

关于java - GridBagLayout 一半组件不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36636251/

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