2
这里我使用的是面板上gridbag
布局添加排列5行5级的部件,我希望他们有不同的高度like this但是这样做如何改变一个网格的最小高度在网格包布局
public void mainpanel3(){
pupper.setBackground(Color.yellow);
ptable.setBackground(Color.BLACK);
lthird.setOpaque(true);
lthird.setBackground(Color.BLUE);
tffourth.setBackground(Color.GREEN);
pfifth.setBackground(Color.WHITE);
outerp3.setLayout(new GridBagLayout());
GridBagConstraints c=new GridBagConstraints();
c.weightx=0.5;
c.weighty=0.5;
c.fill=GridBagConstraints.BOTH;
c.weightx=0.5;
c.weighty=0.1;
c.ipady=5;
c.gridx=0;
c.gridy=0;
outerp3.add(pupper,c);
c.weightx=0.5;
c.weighty=0.4;
c.ipady=20;
c.gridx=0;
c.gridy=1;
outerp3.add(ptable,c);
c.weightx=0.5;
c.weighty=0.1;
c.ipady=5;
c.gridx=0;
c.gridy=2;
outerp3.add(lthird,c);
c.weightx=0.5;
c.weighty=0.1;
c.ipady=5;
c.gridx=0;
c.gridy=3;
outerp3.add(tffourth,c);
c.weightx=0.5;
c.weighty=0.1;
c.ipady=5;
c.gridx=0;
c.gridy=4;
outerp3.add(pfifth,c);
}
后
这发生
第五组分(a panel
)颜色白色不显示出来。
关于此面板的编码仅在此方法中完成,请告诉我您是否需要其他任何代码。
的'weighty'值的所有组件都是一样的。对于每个组件分别将它改为'0.1','0.5','0.1','0.2'和'0.1',以及'gridheight'属性 –