Adding some JPanels (one below another) in JPanel

Go To StackoverFlow.com

3

I'd like to add some panels (with different height) to another JPanel (which is in a JScrollPane) as in this image:

enter image description here

Which layout should I use?

2012-04-05 14:57
by Piotr Sobolewski
Looks like a good fit for <code>BoxLayout</code>. See also A Visual Guide to Layout Managers for a quick 'birds eye view' - Andrew Thompson 2012-04-05 15:00
Ahh!!! I forgot about BoxLayout. Thanks for advice: - Piotr Sobolewski 2012-04-05 15:30
@AndrewThompson Why not put that comment as an answer, its weird to see a question like this;with no answer : - COD3BOY 2012-04-26 10:14
@Sanjay Good point, done. I make 'judgement calls' on each comment/answer at the moment I am posting, and don't always make the best decision. ; - Andrew Thompson 2012-04-26 10:19


2

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.

2012-04-26 10:18
by Andrew Thompson


0

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.

2012-04-05 15:03
by Jens Schauder
Thanks for advice, but FlowLayout is not layout that I search. As Andrew write BoxLayout will resolve the problem - Piotr Sobolewski 2012-04-06 08:11
Ads