I am setting a layout for some buttons. I am trying to have 2 buttons in the middle, and one at the end. I have two in the middle, but the one at the end is off to the side. How can I set the “back” button to be below the other buttons. (I have researched this).
public class Options extends JPanel
{
private static final long serialVersionUID = 1L;
JButton b1 = new JButton("Back");
JButton b4 = new JButton("Textures");
JButton b5 = new JButton("Settings");
public Options()
{
setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.anchor = GridBagConstraints.CENTER;
c.weighty = 1;
c.gridx = 0;
c.gridy = 0;
c.ipadx = 5;
add(b5, c);
c.ipadx = 1;
c.gridy = 1;
add(b4, c);
c.weighty = 1;
c.gridy = 2;
c.anchor = GridBagConstraints.PAGE_END;
add(b1, c);
}
}

EDIT:
I have updated my code above. The offset error has been fixed, but b5 is on top instead of centered (b4 is centerd, b1 is on the bottom).
This should be close enough to the layout I think you are trying to get: