swt窗体居中显示

public static void main(String args[]) {
		try {
			Display display = Display.getDefault();
			shell = new MainShell(display, SWT.SHELL_TRIM);
			shell.setText("数据管理");
			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);
			shell.open();
			shell.layout();
			while (!shell.isDisposed()) {
				if (!display.readAndDispatch())
					display.sleep();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

 

你可能感兴趣的:(SWT)