使用组布局时,您可以使用以下方法设置所有间隙:
setAutoCreateGaps(true);
setAutoCreateContainerGaps(true);
GridBagLayout
是否有相同的功能?
答案 0 :(得分:3)
在GridBagLayout中,使用GridBagConstraints可以使用以下属性设置间隙;
GridBagConstraints.ipadx,GridBagConstraints.ipady: 指定布局中组件的内部填充。
GridBagConstraints.insets: 指定组件的外部填充。
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
答案 1 :(得分:2)
使用隐形JComponents