java Swing 窗口居中
Toolkit kit = Toolkit.getDefaultToolkit(); // 工具包
Dimension screenSize=kit.getScreenSize(); // 获取屏幕的尺寸
setMinimumSize(new Dimension(1300, 700));// 设置一个窗口大小值
Dimension compSize = RoomFrm.this.getSize();
System.out.println(compSize);
System.out.println(screenSize);
if (compSize.height > screenSize.height) {
compSize.height = screenSize.height;
}
if (compSize.width > screenSize.width) {
compSize.width = screenSize.width;
}
//x0=(screenSize.width - compSize.width) / 2;
//y0=(screenSize.height - compSize.height) / 2)
setLocation((screenSize.width - compSize.width) / 2,
(screenSize.height - compSize.height) / 2);