只需要在 ApplicationWorkbenchWindowAdvisor 这个类里的 postWindowOpen方法里写居中的计算方法就好了,主要问题在于,初学者找不到是在这个方法里操作而已,具体的代码如下:
public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
@Override
public void postWindowOpen() {
super.postWindowOpen();
// 居中窗口
Shell shell = getWindowConfigurer().getWindow().getShell();
Rectangle screenSize = Display.getDefault().getClientArea();
Rectangle frameSize = shell.getBounds();
shell.setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
}
}
本文介绍了一种在Eclipse中使UI窗口居中的方法,通过覆盖ApplicationWorkbenchWindowAdvisor类中的postWindowOpen方法实现。具体操作涉及获取窗口尺寸、屏幕尺寸,并设置窗口位置。
2083

被折叠的 条评论
为什么被折叠?



