Use a single GridBagLayout
for both columns rather than splitting apart. GridBagLayout
allows you to do more than just an HTML table would, without having to hack your size and preferred size methods. You can do something as follows in your frame initializer:
getContentPane().setLayout(new GridBagLayout());
GridBagConstraints constraints = null;
Insets insets = new Insets(0, 0, 0, 0);
...
// upper left hand corner, 1 column wide, 2 rows high, make the column take up half of the total width, the row(s) take up 0.66 of the total height
constraints = new GridBagConstraints(0, 0, 1, 2, 0.5, 0.66, GridBagConstraints.CENTER, GridBagConstraints.BOTH, insets, 0, 0);
getContentPane().add(upperLeftPanel, constraints);
// lower left hand corner, 1 column wide, 1 row high, make the column take up half of the total width, the row take up 0.33 of the total height
constraints = new GridBagConstraints(0, 1, 1, 1, 0.5, 0.33, GridBagConstraints.CENTER, GridBagConstraints.BOTH, insets, 0, 0);
getContentPane().add(lowerLeftPanel, constraints);
// upper right hand corner, 1 column wide, 1 row high, make the column take up half of the total width, the row take up 0.33 of the total height
constraints = new GridBagConstraints(1, 0, 1, 1, 0.5, 0.33, GridBagConstraints.CENTER, GridBagConstraints.BOTH, insets, 0, 0);
getContentPane().add(upperRightPanel, constraints);
// center right hand side, 1 column wide, 1 row high, make the column take up half of the total width, the row take up 0.33 of the total height
constraints = new GridBagConstraints(1, 1, 1, 1, 0.5, 0.33, GridBagConstraints.CENTER, GridBagConstraints.BOTH, insets, 0, 0);
getContentPane().add(centerRightPanel, constraints);
// lower right hand corner, 1 column wide, 1 row high, make the column take up half of the total width, the row take up 0.33 of the total height
constraints = new GridBagConstraints(1, 2, 1, 1, 0.5, 0.33, GridBagConstraints.CENTER, GridBagConstraints.BOTH, insets, 0, 0);
getContentPane().add(bottomRightPanel, constraints);
The various properties of the constraints, as well as the container where you will really add the panels is entirely up to you. You can change the same constraints object or create a new one every time. I have see both used, but tend to favor the latter myself. As you can see, there is no problem adding multiple columns to a single GridBagLayout
.