Setup Layout Manager to Swing Container
In this tutorial, we will learn how to setup Layout Manager to Swing Container. We can provide different layouts to the GUI components inside a container. To know more about the different layouts:
Setup Layout Manager
JPanel uses FlowLayout by default and the content pane uses the BorderLayout. We can set the layout when those containers are initialized. We can also change the layout using the setLayout() method when an object had been already created.
To set the layout during the container initialization.
For example, to set BoxLayout to a JPanel::
JPanel panel = new JPanel(new BoxLayout());
After the panel is created, we can change the layout manager by using setLayout() method:
JPanel panel = new JPanel();// JPanel default FlowLayout
Java Tutorial on this website:
For more information on Java, visit the official website :