swing显示屏幕中间方法

 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);
    }

你可能感兴趣的:(swing显示屏幕中间方法)