Swing Layouts
GridBag Layout
We will probably use the GridBag layout most often to layout complicated panels. Here is a list of what the GridBag layout does.
* We can specify which cell we want each component to go in and the component's position on the panel.
* If a component doesn't fill its allotted area, we can tell the GridBag how to position the component within the area.
* The rows and columns don't all have to be the same size. In addition, it automatically adjust the width of each column and the height of each row.
* We can create component that span multiple rows or columns.
* We can tell the GridBag to stretch a component to fill the entire space allotted to it.
For all the GridBag layout constructors and methods, look at the link below " Swing Method & Constructor Table."
Creating a GridBag Layout
JPanel panel = new JPanel();
panel.setLayout(new GridBagLayout());
With a panel that uses a GridBag layout, the add method accepts two parameters: the component to add and a GridBagConstraints object.
GridBagConstraints: It specifies where to place the component in the grid.
When using the GridBagConstraints, we call its constructor and then set any of the fields that we want.

ClickHere to download GridBag.java