java swing 窗口在屏幕中默认显示的位置 居中位置显示

自定义位置
public class Swing_demo2 {

    public static void main(String[] args) {
        JFrame jframe  =new JFrame("标题");
        jframe.setDefaultCloseOperation(jframe.EXIT_ON_CLOSE);
        jframe.setSize(300,300);
        jframe.setLocation(500,300);//在屏幕中设置显示的位置
        jframe.setVisible(true);   //显示

    }

}


居中位置

   那么居中位置要不要去慢慢手动尝试呢,显然不用

public class Swing_demo2 {

    public static void main(String[] args) {
        JFrame jframe  =new JFrame("标题");
        jframe.setDefaultCloseOperation(jframe.EXIT_ON_CLOSE);
        jframe.setSize(300,300);
        jframe.setLocationRelativeTo(null);//在屏幕中居中显示
        jframe.setVisible(true);   //显示

    }

}



posted @ 2018-04-22 13:53  hunterxing  阅读(2066)  评论(0编辑  收藏  举报