I am creating a GUI for an arcade game. It consist of a single JFrame with some JPanels and one JMenu as shown in the figure:
I've been trying using BorderLayout but it doesn't show the panels properly. What I get is that the JMenu shows properly. [1] adjusts its width to content the buttons inside it. The JPanel [2] fulfill almost the rest of the screen. And [3] shows just as a thin line at the end.
Here's the fragment of code that I use to put them in position:
add(new TopMenu(), BorderLayout.PAGE_START); // JMenu
add(new LeftPanel(), BorderLayout.WEST); // [1]
add(new StatusPanel(), BorderLayout.CENTER); // [2]
add(new GameUI(), BorderLayout.LINE_END); // [3]
Any suggestions of what could be provoking this behavior are welcome.
You can always nest JPanels/containers, each using its own layout. So the overall layout could be a BorderLayout with the menu at the BorderLayout.NORTH and the JPanel [1] on the BorderLayout.EAST side, then nest a JPanel into the BorderLayout.CENTER position using either another BorderLayout or a BoxLayout and put your other two JPanels into this JPanel. For instance this CENTER JPanel could use BorderLayout and it could hold JPanel [2] in its BorderLayout.NORTH position and JPanel [3] in its BorderLayout.CENTER position.