You are right.
The dummy column and row fulfil a necessary function.
However, the dummy column and row causes a slight asymmetry.
Here is a brief example of a Dialog with two nested Panels.
The first Panel has an EmptyBorder with Insets (2,2,2,2) the nested Panel an EtchedBorder to show.
Here is the code produced by SwingDesigner with dummy column
- Code: Select all
public class TestDialog
extends JDialog {
private JPanel pnl;
private JPanel pnl_1;
public static void main(String[] args) {
TestDialog dialog = new TestDialog();
dialog.setSize(100, 100);
dialog.setVisible(true);
}
public TestDialog() {
initialize();
}
private void initialize() {
GridBagLayout gridBagLayout = new GridBagLayout();
gridBagLayout.columnWidths = new int[]{0, 0};
gridBagLayout.rowHeights = new int[]{0, 0};
gridBagLayout.columnWeights = new double[]{1.0, 1.0E-4};
gridBagLayout.rowWeights = new double[]{1.0, 1.0E-4};
getContentPane().setLayout(gridBagLayout);
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.BOTH;
gbc.gridx = 0;
gbc.gridy = 0;
getContentPane().add(getPnl(), gbc);
GridBagConstraints gbc_1 = new GridBagConstraints();
gbc_1.fill = GridBagConstraints.BOTH;
gbc_1.gridx = 0;
gbc_1.gridy = 0;
getPnl().add(getPnl_1(), gbc_1);
}
protected JPanel getPnl() {
if (pnl == null) {
pnl = new JPanel();
pnl.setBorder(new EmptyBorder(2, 2, 2, 2));
GridBagLayout gridBagLayout = new GridBagLayout();
gridBagLayout.columnWidths = new int[]{0, 0};
gridBagLayout.rowHeights = new int[]{0, 0};
gridBagLayout.columnWeights = new double[]{1.0, 1.0E-4};
gridBagLayout.rowWeights = new double[]{1.0, 1.0E-4};
pnl.setLayout(gridBagLayout);
}
return pnl;
}
protected JPanel getPnl_1() {
if (pnl_1 == null) {
pnl_1 = new JPanel();
pnl_1.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
GridBagLayout gridBagLayout = new GridBagLayout();
gridBagLayout.columnWidths = new int[]{0};
gridBagLayout.rowHeights = new int[]{0};
gridBagLayout.columnWeights = new double[]{1.0E-4};
gridBagLayout.rowWeights = new double[]{1.0E-4};
pnl_1.setLayout(gridBagLayout);
}
return pnl_1;
}
}
and here without dummy column
- Code: Select all
public class TestDialog
extends JDialog {
private JPanel pnl;
private JPanel pnl_1;
public static void main(String[] args) {
TestDialog dialog = new TestDialog();
dialog.setSize(100, 100);
dialog.setVisible(true);
}
public TestDialog() {
initialize();
}
private void initialize() {
GridBagLayout gridBagLayout = new GridBagLayout();
// gridBagLayout.columnWidths = new int[]{0, 0};
// gridBagLayout.rowHeights = new int[]{0, 0};
// gridBagLayout.columnWeights = new double[]{1.0, 1.0E-4};
// gridBagLayout.rowWeights = new double[]{1.0, 1.0E-4};
gridBagLayout.columnWidths = new int[]{0};
gridBagLayout.rowHeights = new int[]{0};
gridBagLayout.columnWeights = new double[]{1.0};
gridBagLayout.rowWeights = new double[]{1.0};
getContentPane().setLayout(gridBagLayout);
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.BOTH;
gbc.gridx = 0;
gbc.gridy = 0;
getContentPane().add(getPnl(), gbc);
GridBagConstraints gbc_1 = new GridBagConstraints();
gbc_1.fill = GridBagConstraints.BOTH;
gbc_1.gridx = 0;
gbc_1.gridy = 0;
getPnl().add(getPnl_1(), gbc_1);
}
protected JPanel getPnl() {
if (pnl == null) {
pnl = new JPanel();
pnl.setBorder(new EmptyBorder(2, 2, 2, 2));
GridBagLayout gridBagLayout = new GridBagLayout();
// gridBagLayout.columnWidths = new int[]{0, 0};
// gridBagLayout.rowHeights = new int[]{0, 0};
// gridBagLayout.columnWeights = new double[]{1.0, 1.0E-4};
// gridBagLayout.rowWeights = new double[]{1.0, 1.0E-4};
gridBagLayout.columnWidths = new int[]{0};
gridBagLayout.rowHeights = new int[]{0};
gridBagLayout.columnWeights = new double[]{1.0};
gridBagLayout.rowWeights = new double[]{1.0};
pnl.setLayout(gridBagLayout);
}
return pnl;
}
protected JPanel getPnl_1() {
if (pnl_1 == null) {
pnl_1 = new JPanel();
pnl_1.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
GridBagLayout gridBagLayout = new GridBagLayout();
gridBagLayout.columnWidths = new int[]{0};
gridBagLayout.rowHeights = new int[]{0};
gridBagLayout.columnWeights = new double[]{1.0E-4};
gridBagLayout.rowWeights = new double[]{1.0E-4};
pnl_1.setLayout(gridBagLayout);
}
return pnl_1;
}
}
You see the difference of the distances of the etched border between top and bottom and left and right.
Do you get an idea?
Kind regards
Chris