【问题标题】:Centre dialog on the screen in eclipse e4 RCP application immediately when Part is activated激活部件后,在 eclipse e4 RCP 应用程序的屏幕上立即居中对话框
【发布时间】:2015-10-27 16:24:19
【问题描述】:

当我的 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 捆绑。我的问题是,一旦部件被激活,对话框就会显示在显示器的右下角。如果通过单击按钮打开相同的对话框,它会在中心正确显示。任何帮助将不胜感激,在此先感谢!

【问题讨论】:

    标签: eclipse-rcp jface e4


    【解决方案1】:

    使用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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多