`

如何使swt窗口居中显示

 
阅读更多
(1)下面代码可以使swt窗口相对于整个显示器居中
shell.setLocation(Display.getCurrent().getClientArea().width / 2 - shell.getShell().getSize().x/2, Display.getCurrent()
                .getClientArea().height / 2 - shell.getSize().y/2);

(2) 下面代码可以使swt窗口相对于父窗口居中
Rectangle parentBounds = parentShell.getBounds();
Rectangle shellBounds = shell.getBounds();

shell.setLocation(parentBounds.x + (parentBounds.width - shellBounds.width)/2, parentBounds.y + (parentBounds.height - shellBounds.height)/2);

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics