Using BoxLayout
As usual, may setLayout() on a panel to box layout.
Alternatively can use a special container called Box whose default layout is a vertical or horizontal box layout, e.g.:
Box b = Box.createHorizontalBox( ) ;
or
Box b = Box.createVerticalBox( ) ;
You can add components to a box in the usual way
They are flowed into the one dimension. The strategy is to make them fit into one row or column, using the preferred size and alignment if possible, but growing them to maximum size if necessary.
There are invisible fillers available to space the components.