Java – Layouts in java Swing specifying size

javalayoutlayout-managerswing

My question is how can I specify size of the parts on my layout?
I need somehow set size of "parts" not using preferedSize, maybe in layout managers, doesn't matter where – only I need is stable size.

I want to create layout for game. I've already created one but I'm dealing with problem with size of components. So I considered that it would be better to make better concept of my layout.
Let's look at my draft.


+-----------+ 
| UPPER     |
+-----+-----+
|  A  |     |
+-----+  C  |
|  B  |     |
+-----+-----+
| Footer    |
+-----------+

A+B+C make together Center.

Main part consist of this tree parts:
Upper- there will be menu.
Center – this consists of 3 parts A,B,C
Footer – there will be status bar

My idea is to be able to set the size of each component.
All layout is dependent on part C it could have size 450×450 px or 600×600 px.
For part A and B i need specify only the width, because there will be only some text info – it should be about 300 px.
I tryed to use GridBagLayout for Center part but setSize for C didn't worked well.
I make the parts in Containers (java.awt.Container) – in them I add the content of each part and then add the Container to the upper level.

Best Answer

The simplest way: use BorderLayout for the contentPane (which already is) - Upper panel goes to North - Footer panel goes to South - Panels A and B goes into a Panel ab with GridLayout(2,1) - Panel ab and C goes into a Panel abc with GridLayout(1,2) - Panel abc goes into the Center And setPrefferedSize() of your A, B, C