Java 为什么不是';运行此GUI程序时,框架是否以该程序为中心?

Java 为什么不是';运行此GUI程序时,框架是否以该程序为中心?,java,swing,user-interface,Java,Swing,User Interface,在这里,我尝试使用方法setLocationRelativeTo(null)将帧居中

在这里,我尝试使用方法
setLocationRelativeTo(null)将帧居中移动

package guilabq;

import java.awt.*;
import javax.swing.*;

public class GUI {

    JFrame f=new JFrame();//Creating a frame
    JTextArea area=new JTextArea();
    JScrollPane scroll=new JScrollPane(area);
    JRadioButton b1=new JRadioButton("Wrap");
    JRadioButton b2=new JRadioButton("Wrap Words");
    JRadioButton b3=new JRadioButton("Wrap Characters");
    ButtonGroup grp=new ButtonGroup();
    JPanel p1=new JPanel();//Creating a panel

    GUI() {
        grp.add(b1);
        grp.add(b2);//Grouping the buttons
        grp.add(b3);

        p1.add(b1);
        p1.add(b2);
        p1.add(b3);
        p1.setLayout(new GridLayout(1,3));
        p1.setBorder(new TitledBorder("Wrap Options"));

        f.add(scroll,BorderLayout.CENTER);
        f.add(p1,BorderLayout.SOUTH);

        f.setLocationRelativeTo(null);//Here I have tried to center the frame                                                
        f.pack();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setSize(400, 300);
        f.setVisible(true);
    }

    public static void main(String[]args) {
        new GUI();
    }
}
之后

f.setLocationRelativeTo(null);//Here I have tried to center the frame
像这样:

f.setSize(400, 300);
移动

之后

f.setLocationRelativeTo(null);//Here I have tried to center the frame
像这样:

f.setSize(400, 300);