Using FlowLayout
This simple layout manager “flows” components into the window.
Row “justification”, and space between components specified, by optional align, hgap and vgap arguments of constructor, e.g.:
setLayout(new FlowLayout(FlowLayout.LEFT, 5, 2)) ;
setLayout(new FlowLayout(FlowLayout.CENTER)) ;
setLayout(new FlowLayout(FlowLayout.RIGHT)) ;
The flow layout manager’s strategy includes trying to make each component its “preferred size”.