views:

287

answers:

1

I have two JPanels (let's call these Panel1 and Panel2). These panels are of the same width, but varying heights.

I want to put these JPanels into one big JPanel (lets call it Panel0), and stack them on top of each other (I decided to set Panel0's layout as GridLayout(0,1)).

The problem, is that both nested panels (panels 1 and 2) end up having the same dimensions (those of the biggest between the two), instead of the setPreferredDimension and setDimension that I set to them.

Sorry, I can't really provide any code (there's a lot of crap added to the panel's, and it's all for something work-related). Any advice? Thanks!

+3  A: 

GridLayout forces all components to be the same size; that's why it's called a grid.

Since you only have two panels, I'd suggest using a BorderLayout with one panel at NORTH and the other CENTER. If you allow resizing, then the one in CENTER will be the expand to fill any extra vertical space, so just be aware of that.

Michael Myers
I was half way done typing up this same response. GridLayout is the problem.
thedude19
Oh wow, works great! Thanks!
Monster