GridBag布局的一半组件不可见

时间:2016-04-15 00:19:17

标签: java swing jpanel layout-manager gridbaglayout

我正在尝试创建一个3 x 4网格的jpanel。 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

1 个答案:

答案 0 :(得分:1)

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作为底部面板。