如何使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);



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章