protected void createContents() {
shell = new Shell();
shell.setSize(800, 600);
shell.setText(title);
int width=shell.getDisplay().getBounds().width; // 找到createContents这个方法,得到屏幕的宽度。
int height=shell.getDisplay().getBounds().height; // 在这个方法中,得到屏幕的高度。
// 得到屏幕的宽高度减去shell窗口的宽度和高度,除以2得到窗口的左上角坐标。
int x=(width-shell.getBounds().width)/2;
int y=(height-shell.getBounds().height)/2;
shell.setLocation(x, y);}
标签:shell,Java,int,eclipse,height,width,getBounds,屏幕
From: https://blog.51cto.com/emanlee/8203521