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