2012-10-09 80 views

回答

3

在GridBagLayout中,使用GridBagCons你可以通過下面的屬性設置差距;

  1. GridBagConstraints.ipadx,GridBagConstraints.ipady: 指定佈局中的組件的內部填充。

  2. GridBagConstraints.insets: 指定組件的外部填充。

  3. GridBagConstraints.weightx,GridBagConstraints.weighty: 用於確定如何分配空間。

例如:

pane.setLayout(new GridBagLayout()); 
GridBagConstraints c = new GridBagConstraints(); 
c.fill = GridBagConstraints.HORIZONTAL; 
c.ipady = 40;  //make this component tall 
c.ipadx = 10;  //make this component wide 
c.anchor = GridBagConstraints.PAGE_END; //bottom of space 
c.insets = new Insets(10,0,0,0); //top padding 
c.gridx = 1;  //first column 
c.gridy = 2;  //third row 
c.gridwidth = 2; //2 columns wide 
c.weightx = 0.5; //increase horizontal space 
c.weighty = 1.0; //increase vertical space 
相關問題