swing显示屏幕中间方法

来源:互联网 发布:培训班java教哪些课程 编辑:程序博客网 时间:2024/05/18 01:23
 public static void setLocationCenter(JFrame frame) {        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();        Dimension compSize = frame.getSize();        if (compSize.height > screenSize.height) {            compSize.height = screenSize.height;        }        if (compSize.width > screenSize.width) {            compSize.width = screenSize.width;        }        frame.setLocation((screenSize.width - compSize.width) / 2,                (screenSize.height - compSize.height) / 2);    }

原创粉丝点击