可能重复:
Swing:如何将组件高度设置为容器的高度?
我如何划分JPanel,如下图所示有2个面板panel1和panel2 panel1应该占70%,panel2 30%或panel1应该大于panel2...我尝试过Gridlayout,Border Layout但它不起作用。任何帮助将不胜感激。
public class TestApplication extends JApplet {
private static final long serialVersionUID = 1L;
JPanel p1,p2;
public void init(){
setLayout(new GridLayout(3,1));
p1=new JPanel();
p2=new JPanel();
p1.setBackground(Color.RED);
p2.setBackground(Color.GREEN);
add(p1);
add(p2);
}
}