3

当您使用组布局时,您可以使用以下方式设置所有间隙:

setAutoCreateGaps(true);
setAutoCreateContainerGaps(true);

有相同的功能GridBagLayout吗?

4

2 回答 2

5

在 GridBagLayout 中,使用 GridBagConstraints 您可以使用以下属性设置间隙;

  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
于 2012-10-11T10:49:39.910 回答
2
于 2012-10-09T09:03:08.993 回答