Java Swing BorderLayout

In this tutorial, we will show you how to work with swing border layout using BorderLayout class.

Here is the screenshot of demo application using BorderLayout.

Java BorderLayout

The BorderLayout divides the container into five areas which include: PAGE_START, PAGE_END, LINE_START, CENTER and LINE_END.

You can use the constants of BorderLayout class to indicate the area where you want to place a component. If you enlarge the window, you can see that the center area take up as much of space as possible and the other areas only expand to fill available space.

You can set the horizontal and vertical gap between components by using methods setHgap() and setVgap().

Here is the source code of demo application:

  • Was this tutorial helpful ?
  • YesNo