SWT 使窗体程序居中显示

来源:互联网 发布:2017年java工程师工资 编辑:程序博客网 时间:2024/05/16 17:29
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);}}

0 0