I'd like to add some panels (with different height) to another JPanel
(which is in a JScrollPane
) as in this image:
Which layout should I use?
Looks like a good fit for BoxLayout
. See also A Visual Guide to Layout Managers for a quick 'birds eye view' of the layouts available in the J2SE.
Possibly the easiest is to use flowlayout and set the preferred height of the JPanels accordingly http://docs.oracle.com/javase/tutorial/uiswing/layout/flow.html
If you plan to do more with your layout I'd recommend one of the more advanced third party layouts like JGoodies Form Layout http://www.jgoodies.com/freeware/forms/ You'll need to learn more, but than you have a good flexible layout which will solve most of the real world problems you'll see.