Border layout is one of the simplest layout managers. The way to use a layout manager is to set the manager of a JPanel.
Border Layout slots follow the following rules:
North & South: preferred height
East & West: preferred width
Center: maximum remaining space
In BorderLayout slots can also be empty. The layout manager will automatically compensate for any empty spaces, resizing when needed.
Here is what this example looks like:
Flow layout is the simplest layout manager that Swing has to offer. Flow layout tries to put everything on one line, and if the layout overflows the width, it will wrap the line. The order is specified by the order you add components to your panel.
The GridLayout allows you to arrange components in the form of a grid.
You pass the number of rows and columns you want the grid to have to the GridLayout's constructor, for example new GridLayout(3, 2) will create a GridLayout with 3 rows and 2 columns.
When adding components to a container with the GridLayout, the components will be added row by row, from left to right:
This creates and shows a JFrame that looks like:
A more detailed description is available: GridLayout
This modified text is an extract of the original Stack Overflow Documentation created by following contributors and released under CC BY-SA 3.0