'JFrame and JPanel sizing

I have a JFrame and a few JPanels that are displayed depending on where the user goes (to login, homepage etc), is there a way to set all JPanels to the same size without having to manually specify?

public mainApp() {
    main = new JFrame("Application");
    main.setSize(640, 480);
    main.setVisible(true);
}

private JPanel loginScreen() {
    login = new JPanel(null);
    login.setSize(640, 480);
    login.setVisible(true);
    
}

For example I have 5 different JPanels, and have to specify the size in each, is there a way to set a default size that is the same as the JFrame?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source