I am just trying to add 3 centered vertical buttons to a GridBagLayout in java swing. Right now I believe the default grid size is 3×3. I wanted to know if I can change that and add more columns and rows. I simply want to make 3 centered equally spaced butons in a pane.
pane.setLayout(new GridLayout(10,1));
// Insert a space before the first button
for (int i = 1; i < 6; i++ ){
pane.add(new JLabel(""));
}
pane.add(new Button("1"));
pane.add(new Button("2"));
pane.add(new Button("3"));
// Insert a space after the last button
pane.add(new JLabel(""));
That was the final solution Thanks everyone!
I agree with @Chris a
GridLayoutwould be easier: