I'm still trying to figure out BorderLayout in JavaSwing, and it's really frustrating.
I want to be able to split a pane into 3 contained sub-panels, but I'm not entirely sure how to contain it.
Here is my class Game, which contains panels ControlPanel, StatePanel, and Board (really just an extension of JPanel). I want to split the panel into those three sections like this:
Here is my code so far:
public class Game extends JPanel {
private int panespace=2;
private JPanel ControlPanel;
private JPanel StatePanel;
private Board board;
public Game()
{
setLayout(new BorderLayout(panespace, panespace));
ControlPanel=new JPanel();
ControlPanel.setLayout(new BorderLayout(panespace, panespace));
ControlPanel.setBorder(new LineBorder(Color.red, 10));
ControlPanel.setSize(100,100);
super.add(ControlPanel, BorderLayout.EAST);
StatePanel=new JPanel();
StatePanel.setLayout(new BorderLayout(panespace, panespace));
StatePanel.setBorder(new LineBorder(Color.green, 10));
StatePanel.setSize(200, 200);
super.add(StatePanel, BorderLayout.EAST);
board = new Board();
board.setLayout(new BorderLayout(panespace, panespace));
board.setBorder(new LineBorder(Color.yellow, 10));
board.setSize(300, 300);
super.add(board, BorderLayout.NORTH);
setVisible(true);
}
}
Preferably, this would use BorderLayout, but I seem to be doing it incorrectly. I've tried reading the materials that Oracle provides, but they haven't been particularly helpful. At this point, I am at the point where I want to hard code values in, but I know that I should be able to split it to have each panel take up as much of the larger Game panel as possible.