my three bottons is not centering
Code :
import java.awt.BorderLayout;
import java.awt.Image;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class optionButton{
public JButton shop;
public JButton exit;
public Image leftButtonIcon;
public Image bg;
public JPanel p;
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
public optionButton(){
JFrame contentPane = new JFrame();
contentPane.setSize(700, 700);
contentPane.setVisible(true);
JButton button = new JButton("Button 1 (PAGE_START)");
JButton button1 = new JButton("Button 1 (PAGE_START)");
JButton button2= new JButton("Button 1 (PAGE_START)");
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BoxLayout(mainPanel , BoxLayout.Y_AXIS));
mainPanel.add(button);
mainPanel.add(button1);
mainPanel.add(button2);
contentPane.add(mainPanel , BorderLayout.CENTER);
}
public static void main(String[] args) {
new optionButton();
}
}
My three button in the boxlayout is not going to the center when I call the border layout center