Use FlowLayout

The FlowLayout layout manager arranges components in a left-to-right flow, with wrapping lines. The advantages of the flow layout manager include its ease of use, and the guarantee that each component can be seen.

The FlowLayout layout manager (java.awt.FlowLayout) dynamically sizes each component according to its preferred size. It positions components so that they are evenly spaced. Flow layouts are typically used to arrange buttons in a panel. It will arrange buttons left to right until no more buttons fit on the same line. Each line is centered by default, unless alignment is set to left or right.

FlowLayout is the default layout manager for a JPanel.

 

Parent topic

Swing and AWT layout managers

 

Related concepts

Layout managers and containers

 

Related tasks

Using BorderLayout
Using BoxLayout
Using CardLayout
Using GridLayout (AWT)
Using GridBag layout