在
GridBagLayout
中,是否可以为整个行/列设置margin/padding?我使用约束对象上的inset,但是使用这种方法,我需要在每个组件上单独设置底部间距。是否可以对
JFrame
中的所有内容进行填充?因为现在每个组件都与框架对齐。
constraints.weightx = 2;
constraints.weighty = 1;
constraints.fill = GridBagConstraints.BOTH;
addComponent(this, layout, constraints, questionPanel = new QuestionPanel(), 0, 0, 1, 1);
constraints.weightx = 1;
constraints.weighty = 1;
constraints.fill = GridBagConstraints.BOTH;
addComponent(this, layout, constraints, categoryPanel = new CategoryPanel(), 0, 1, 1, 1);
constraints.weightx = 1;
constraints.weighty = 0;
constraints.fill = GridBagConstraints.HORIZONTAL;
addComponent(this, layout, constraints, answerPanel = new AnswerPanel(), 1, 0, 2, 1);
constraints.weightx = 1;
constraints.weighty = 2;
constraints.fill = GridBagConstraints.BOTH;
addComponent(this, layout, constraints, tabPane = new JTabbedPane(), 2, 0, 2, 1);
constraints.weightx = 1;
constraints.weighty = 0;
constraints.fill = GridBagConstraints.NONE;
constraints.anchor = GridBagConstraints.SOUTHEAST;
addComponent(this, layout, constraints, buttonPanel = new ButtonPanel(), 3, 1, 1, 1);
我正在使用一个私有方法 addComponent:
private void addComponent(Container context, GridBagLayout _layout, GridBagConstraints _constraints, Component component, int row, int column, int width, int height) {
_constraints.gridx = column;
_constraints.gridy = row;
_constraints.gridwidth = width;
_constraints.gridheight = height;
_layout.setConstraints(component, _constraints);
context.add(component);
}
我该如何在单元格之间添加一些"空隙(内/外边距)"?