Setting Gap Sizes in a GridBadLayout

Unlike most of the other layout managers, the gridbag layout manager does not have a property for controlling the size of the gaps between cells. You could implement gaps using insets (see Setting the Space around a Component Within the Cell of the GridBagLayout Using Insets. However, this method is tedious and any change in the layout requires major changes with the insets.

The next best method is to create a blank column or row explicitly for the desired gaps.

// Assume components have been added in cells // (0,0), (0,2), (2,0), (2,2) // Create a 10 pixel gap between columns 0 and 2 setColumnMinWidth(gbl, 1, 10); // Create a 10 pixel gap between rows 0 and 2 setRowMinHeight(gbl, 1, 10); // setColumnMinWidth() and setRowMinHeight() are defined in // Setting a Row or Column of a GridBadLayout to a Particular Size

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.