swing窗口居中或不居中

1、窗口居中的两种办法

  A、centerToScreen();方法

  B、  int windowWidth = frame.getWidth(); //获得窗口宽

     int windowHeight = frame.getHeight(); //获得窗口高
    Toolkit kit = Toolkit.getDefaultToolkit(); //定义工具包
    Dimension screenSize = kit.getScreenSize(); //获取屏幕的尺寸
    int screenWidth = screenSize.width; //获取屏幕的宽
    int screenHeight = screenSize.height; //获取屏幕的高
    frame.setLocation(screenWidth/2-windowWidth/2, screenHeight/2-windowHeight/2);//设置窗口居中显示

2、不居中,也就是使用frame.setLocation()来进行调试

原文地址:https://www.cnblogs.com/wwssgg/p/15077087.html