Java eclipse中shell窗口怎么居中显示

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);

}

原文地址:https://www.cnblogs.com/emanlee/p/13340637.html