I’m pulling my hair out trying to learn these layout managers.
Does anyone know what may be the problem here?
This is what I’m getting:
http://imageshack.us/a/img685/5589/gridbag.png
This is what I’m trying to create:
http://imageshack.us/a/img528/2870/gridbaggood.png
Here’s the code:
public void createPanel() {
this.setVisible(true);
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(4, 4, 4, 4);
JTable puzzleLabel = new JTable(null);
JLabel usersLabel = new JLabel("Sudoku");
JPanel southPanel = new JPanel();
JPanel westPanel = new JPanel();
JPanel detailsPanel = new JPanel();
detailsPanel.setLayout(new GridBagLayout());
//Button panel button set
gbc.gridx = 0;
gbc.gridy = 0;
detailsPanel.add(new JButton("Button"), gbc);
gbc.gridx = 0;
gbc.gridy = 1;
detailsPanel.add(new JButton("Button"), gbc);
gbc.gridx = 0;
gbc.gridy = 2;
detailsPanel.add(new JButton("Button"), gbc);
/////////////////////////
gbc.gridx = 0;
gbc.gridy = 0;
this.add(westPanel, gbc);
gbc.gridx = 1;
gbc.gridy = 0;
gbc.anchor = GridBagConstraints.WEST;
this.add(usersLabel, gbc);
gbc.gridx = 1;
gbc.gridy = 1;
this.add(new JScrollPane(puzzleLabel), gbc);
gbc.gridx = 1;
gbc.gridy = 2;
this.add(southPanel, gbc);
gbc.gridx = 2;
gbc.gridy = 1;
this.add(detailsPanel, gbc);
}