Why does my frame shrink once I `setDefaultCloseOperation(false)`?

Viewed 30

I have tried to setDefautCloseOperation(false) for my frame login. But the frame shrinks down to be practically invisible. Why does this happen? I have encountered this problem many times. Sometimes, when I re-arrange my code it works, but I want to know how to get over this issue? Is it because of the nature of the swing package?

Here is my code:

package tester_project;

import javax.swing.JFrame;

public class Main {

    public static void main(String[] args) {
        
        JFrame login = new JFrame();
        login.setTitle("Login");
        login.setVisible(true);
        login.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        login.setSize(500, 500);
        login.setResizable(false);
    }

}

But when I move up the setDefaultCloseOperation(false); it works:

package tester_project;

import javax.swing.JFrame;

public class Main {

    public static void main(String[] args) {
        
        JFrame login = new JFrame();
        login.setTitle("Login");
        login.setVisible(true);
        login.setResizable(false);
        login.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        login.setSize(500, 500);
    }

}

Does this happen because java supports procedural code? I am new to java so my question might seem trivial, but can someone explain to me why this is happening?

0 Answers
Related