现在,这个问题已经得到澄清:
protected static final Insets entryInsets = new Insets(0, 10, 4, 10);
protected static final Insets spaceInsets = new Insets(10, 10, 4, 10);
protected void createPartControl() {
panel = new JPanel();
panel.setLayout(new GridBagLayout());
int gridy = 0;
gridy = createTextFields(gridy);
}
protected int createTextFields(int gridy) {
JLabel a = new JLabel("A");
a.setHorizontalAlignment(SwingConstants.LEFT);
addComponent(panel, a, 0, gridy, 1, 2, spaceInsets,
GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL);
JLabel b = new JLabel("B");
b.setHorizontalAlignment(SwingConstants.LEFT);
addComponent(panel, b, 1, gridy++, 1, 1, spaceInsets,
GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL);
JLabel c = new JLabel("C");
c.setHorizontalAlignment(SwingConstants.LEFT);
addComponent(panel, c, 1, gridy++, 1, 1, entryInsets,
GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL);
JLabel d = new JLabel("D");
d.setHorizontalAlignment(SwingConstants.LEFT);
addComponent(panel, d, 0, gridy++, 2, 1, entryInsets,
GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL);
return gridy;
}
protected void addComponent(Container container, Component component,
int gridx, int gridy, int gridwidth, int gridheight,
Insets insets, int anchor, int fill) {
GridBagConstraints gbc = new GridBagConstraints(gridx, gridy,
gridwidth, gridheight, 1.0D, 1.0D, anchor, fill, insets, 0, 0);
container.add(component, gbc);
}
你应该张贴一些代码,所以我们看到你正在尝试做的。 – SJuan76
嗯。让我看看我是否可以清理方法稍微更一般。 现在让我试着解释它一些: (高度和宽度代表gridbag约束) 我有几个用户创建表与高度1-10和宽度1-2 – Phox
你可以显示一些屏幕截图和一些代码?现在的问题太抽象了。 –