您的位置:首页 > 其它

Swing中如何将窗口显示在屏幕正中间

2011-04-21 20:56 381 查看
自己写的一个小方法

public static void setLocationCenter(Component component) {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension compSize = component.getSize();
if (compSize.height > screenSize.height) {
compSize.height = screenSize.height;
}
if (compSize.width > screenSize.width) {
compSize.width = screenSize.width;
}
component.setLocation((screenSize.width - compSize.width) / 2,
(screenSize.height - compSize.height) / 2);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: