//使对话框居中的函数,不会因为分辨率不同而位置不同
public static void setLocation(JDialog dialog) {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = dialog.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
dialog.setLocation( (screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
}
//要想调用此函数,只要在Dialog中使用
JBGlobal.setLocation(this);
//JBGlobal是全局类,还要注意的是上面的语句要在
this.setSize(new Dimension(500, 395));
//后面,否则对话框不会居中。
public static void setLocation(JDialog dialog) {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = dialog.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
dialog.setLocation( (screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
}
//要想调用此函数,只要在Dialog中使用
JBGlobal.setLocation(this);
//JBGlobal是全局类,还要注意的是上面的语句要在
this.setSize(new Dimension(500, 395));
//后面,否则对话框不会居中。