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);   //显示

    }

}




免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM