现在问题已经澄清:
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);
}