So I have aligned everything in my program using the BoxLayout, but when I run the GUI the components fill the whole screen and are not centrally aligned. I was just wondering how I could change the size of them all and align everything centrally
import javax.swing.*;
public class NewMain {
JFrame window = new JFrame();
JPanel login = new JPanel();
JTextField username = new JTextField("Username", 15);
JTextField password = new JTextField("Password", 15);
JButton sendLogin = new JButton("Login");
JLabel data = new JLabel("aaaaaaaaaaaaaaaa");
public NewMain() {
login.setLayout(new BoxLayout(login, BoxLayout.PAGE_AXIS));
login.add(username);
login.add(password);
login.add(sendLogin);
login.add(data);
window.add(login);
window.setVisible(true);
window.setSize(800, 500);
window.setLocationRelativeTo(null);
window.setResizable(false);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setTitle("Title");
}
public static void main(String[] args) {
new NewMain();
}
}