I have an annoying issue with my JPanels that use BorderLayout.
this.setLayout(new BorderLayout(0, 0));
JPanel panel = new JPanel(new BorderLayout(0, 0));
panel.add(new Slot(), BorderLayout.SOUTH);
panel.add(new MapGUI(), BorderLayout.NORTH);
this.add(panel, BorderLayout.CENTER);
This is in the constructor of my Inventory JPanel. Slot() and MapGUI() are classes that extend JPanel. When the game runs, the screen looks like this:
Clearly the Panels are completely off, with both being off the screen. How can I fix this? Thanks for any help.
According to the JavaDocs for the BorderLayout:
The components are laid out according to their preferred sizes and the constraints of the container's size. The NORTH and SOUTH components may be stretched horizontally; the EAST and WEST components may be stretched vertically; the CENTER component may stretch both horizontally and vertically to fill any space left over.
Do you have the preferred sizes set?
You may want to try the BoxLayout if you want to align the components vertically.