SWT中使子窗体居中显示
public class FrameCenter {
public static void setFrameCenter(Shell shell){
int width = shell.getMonitor().getClientArea().width;
int height = shell.getMonitor().getClientArea().height;
int x = shell.getSize().x;
int y = shell.getSize().y;
if (x > width) {
shell.getSize().x = width;
}
if (y > height) {
shell.getSize().y = height;
}
shell.setLocation((width - x) / 2, (height - y) / 2);
}
public static void setdileCenter(Shell shell){
int width = shell.getMonitor().getClientArea().width;
int height = shell.getMonitor().getClientArea().height;
int x = shell.getSize().x;
int y = shell.getSize().y;
if (x > width) {
shell.getSize().x = width;
}
if (y > height) {
shell.getSize().y = height;
}
shell.setLocation((width - x) / 2, (height - y) / 2);
}
}
SWT 使窗体程序居中显示
最新推荐文章于 2017-04-22 22:58:01 发布