JPanel panel = new JPanel(); panel.setLayout(new BoxLayout()); JButton button = new JButton("Button"); button.setAlignmentX(Component.CENTER_ALIGNMENT); panel.add(button); new JFrame.add(panel);