The fact you use a JScrollPane
changes quite a few things concerning the internal FlowLayout
. indeed, when the FlowLayout tries to layout contained JButtons, it use for that the available space. In your case, you don't have limits to the space in the "scrollable client" of your JScrollPane. As a consequence, considering your FlowLayout has infinite space, it uses this space to display items according to it.
So the solution would be to change your scrollable client in order to limit its viewable area to the same than your JScrollPane's JViewport
.
However, you would not even in this case have your line returns, as FlowLayout don't really well handle this case.
Were I to be you, I would of course choose an other layout. As GridLayout
don't really well handles borders, i think the only reasonible standard layout you can use is GridBagLayout
, althgough I fear your dynamic content constraints may require you something even more customizable.