当 Part 被激活时,立即在 eclipse e4 RCP 应用程序的屏幕上居中对话框
Centre dialog on the screen in eclipse e4 RCP application immediately when Part is activated
当我的 Eclipse RCP 应用程序中的左部分被激活时,我正在打开一个对话框。
在 Part 的 @PostConstruct 方法中,我将 IPartListner 注册到 EPartService。
以下代码显示:
partService.addPartListener(new IPartListener() {
@Override
public void partActivated(MPart part) {
if(part.getElementId().equals("left_part_id")) {
SignInDialog dialog = new SignInDialog(shell, display, eventBroker);
dialog.open();
}
}
});
在扩展 JFace 对话框的 SignInDialog 中,我正在这样做:
@Override
protected void configureShell(Shell newShell) {
Monitor monitor = display.getPrimaryMonitor();
Rectangle monitorRect = monitor.getBounds();
int x = monitorRect.x + (monitorRect.width - 600) / 2;
int y = monitorRect.y + (monitorRect.height - 360) / 2;
newShell.setLocation(x, y);
newShell.setText("Sign In");
super.configureShell(newShell);
}
@Override
protected Point getInitialSize() {
return new Point(600, 360);
}
请注意,左侧部分始终可见并通过 Application.e4xmi 捆绑。我的问题是,一旦部件被激活,对话框就会显示在监视器的右下角。如果通过单击按钮打开相同的对话框,它会在中心正确显示。任何帮助将不胜感激,提前致谢!
使用getInitialLocation
方法设置对话框的位置。 configureShell
中设置的大小已被默认值 getInitialLocation
覆盖
@Override
protected Point getInitialLocation(final Point initialSize)
{
Display display = getShell().getDisplay();
Monitor monitor = display.getPrimaryMonitor();
Rectangle monitorRect = monitor.getBounds();
int x = monitorRect.x + (monitorRect.width - 600) / 2;
int y = monitorRect.y + (monitorRect.height - 360) / 2;
return new Point(x, y);
}
当我的 Eclipse RCP 应用程序中的左部分被激活时,我正在打开一个对话框。 在 Part 的 @PostConstruct 方法中,我将 IPartListner 注册到 EPartService。 以下代码显示:
partService.addPartListener(new IPartListener() {
@Override
public void partActivated(MPart part) {
if(part.getElementId().equals("left_part_id")) {
SignInDialog dialog = new SignInDialog(shell, display, eventBroker);
dialog.open();
}
}
});
在扩展 JFace 对话框的 SignInDialog 中,我正在这样做:
@Override
protected void configureShell(Shell newShell) {
Monitor monitor = display.getPrimaryMonitor();
Rectangle monitorRect = monitor.getBounds();
int x = monitorRect.x + (monitorRect.width - 600) / 2;
int y = monitorRect.y + (monitorRect.height - 360) / 2;
newShell.setLocation(x, y);
newShell.setText("Sign In");
super.configureShell(newShell);
}
@Override
protected Point getInitialSize() {
return new Point(600, 360);
}
请注意,左侧部分始终可见并通过 Application.e4xmi 捆绑。我的问题是,一旦部件被激活,对话框就会显示在监视器的右下角。如果通过单击按钮打开相同的对话框,它会在中心正确显示。任何帮助将不胜感激,提前致谢!
使用getInitialLocation
方法设置对话框的位置。 configureShell
中设置的大小已被默认值 getInitialLocation
@Override
protected Point getInitialLocation(final Point initialSize)
{
Display display = getShell().getDisplay();
Monitor monitor = display.getPrimaryMonitor();
Rectangle monitorRect = monitor.getBounds();
int x = monitorRect.x + (monitorRect.width - 600) / 2;
int y = monitorRect.y + (monitorRect.height - 360) / 2;
return new Point(x, y);
}