【发布时间】:2014-06-04 00:29:11
【问题描述】:
这是我的代码:
JPanel panel = new JPanel();
JPanel p = new JPanel(new GridBagLayout());
p.setBackground(Color.green);
GridBagConstraints c1 = new GridBagConstraints();
c1.insets = new Insets(0, 0, 0, 0);
c1.anchor = GridBagConstraints.WEST;
int index = 0;
int i2 = 0;
for(String[] data : attribute.choices){
JCheckBox checkbox = new JCheckBox(data[0]);
checkbox.setBackground(Color.red);
checkbox.setSelected(false);
c1.gridx = index % 2;
c1.gridy = index / 2;
p.add(checkbox, c1);
index++;
}
panel.add(p);
结果如下:
.
我希望复选框(红色区域)位于右侧。我该怎么做?
【问题讨论】:
标签: java swing alignment gridbaglayout