组:一些组件的集合
                      连续组:一个接着一个摆放
                      并行组:一个组在另一个组的顶部
                      水平方向:连续组b1,b2.并行组g1{b3,b4}
                       垂直方向:连续组{b1,b2,b3},b4  
效果图:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKoAAABGCAYAAABc8A97AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAiOSURBVHhe7dz7UxNXFAfw/Es7/g9tf1Ux8EPbP6DtTMexFRF/abWtr9qiIjGAPHzVTsepjqNoFN/KQ6yKqUQMgrwdQcBCRe2c3nN2b7IJJ49NstG7e5n5DCRnCWfv+WZRCDdwtG8a2u9MQmvPOBzqGoWm28+g8eYwHLzxlISui/fXh8THQxAWtxtvmppuPYVDt4ah5fYwtHaNQJvQ3j0Ch3uewVHhWO8zON47Cr/dEfpG4QQZg9/vFg4/vxD49TPC/oTjORyTxDmhownifCXr3O2OWHBdDvfg+pjakVgvqc3OWk+Ea2vXcjvpEBIzQM1pmjLA2YbF/HCeDWKuB64NQf21OOy/Goe9V57Ar5efwC+dg7BH2H3pMeyKPIYdFx7D9vMx+FH4ocO07dwA2Wr5/tyj/J3N7bs0gSN9U9DWOwGt3WOJoIbTghrCoNrCKgPbJDRbgT0kArsitIIcFLEP1YGUx3DIDEgG3ab2LNqkrnQ5AmVDgRJrIzUjsWb2QDVKYu3lxcBOrjuSs8GZ4GzsMHwNInwSBtFOhhLtE8FMD+fPl0RALyYDuuOCGVAZ0m0dZkBlSNkgckTY8pEeUClgXk0noEUEtRmvprdGkkG1QirJsKYHFpmhNZ/didDie2twUsqVIw/2z3WipQu/dgZWf8geoHQUKCTOKfUqZX5HQfYwIbxaSYlAWWsWQrb1pFBJIkSmuAhUUr0IlB2FTIQLQ2aHgSMidFKdDYaRiDBiKFOCKezCcAo7KZzJK2hKQK2QbuWCmIkIWS5cMNMFWsXVFEOauJpiUG+YQZVX03T2wGYKLaFhJgcsB56vJvGEKYQ9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*/
package com.niit.javagui; import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JFrame; /**
* @author: Annie
* @date:2016年5月31日
* @description:
*/
public class GroupLayoutDemo extends JFrame{ JButton b1,b2,b3,b4;
public GroupLayoutDemo() {
setVisible(true);
setSize(400,400);
setTitle("GroupLayoutDemo");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GroupLayout layout = new GroupLayout(getContentPane());
setLayout(layout);
b1 = new JButton("b1");
b2 = new JButton("b2");
b3 = new JButton("b3");
b4 = new JButton("b4");
//创建一个连续组对象 作为水平方向的布局
GroupLayout.SequentialGroup sg1 = layout.createSequentialGroup();
sg1.addComponent(b1);
sg1.addComponent(b2); //b3和b4并行的小组
GroupLayout.ParallelGroup pg1=layout.createParallelGroup();
pg1.addComponent(b3);
pg1.addComponent(b4);
sg1.addGroup(pg1);
//指定水平方向布局是sg1
layout.setHorizontalGroup(sg1); GroupLayout.SequentialGroup sg2 = layout.createSequentialGroup();
GroupLayout.ParallelGroup pg2=layout.createParallelGroup();
pg2.addComponent(b1);
pg2.addComponent(b2);
pg2.addComponent(b3);
sg2.addGroup(pg2);
sg2.addComponent(b4);
layout.setVerticalGroup(sg2);
}
public static void main(String[] args) {
new GroupLayoutDemo();
}
}
05-08 07:59