如何根据WizardPage调整WizardDialog?

发布于 2025-02-10 05:02:45 字数 701 浏览 0 评论 0原文

我正在创建一个Jface WizardDialog,其中包括一个根据用户选择,它正在更改其内容(控件)的单个WizardPage。简而言之:

final PageAccess page = new PageAccess(...);

WizCreate wiz = new WizCreate() {
    @Override
    public boolean performFinish() {
        page.performFinish();
        return true;
    }
};
wiz.addPage(page);

Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
WizardDialog dialog = new WizardDialog(shell, wiz);
dialog.open();

PageAccess扩展了WizardPage,Wizcreate扩展了向导。

页面中的所有复合材料均使用gridlayout。 该页面实现了selectionListener,并重新绘制其内容。 当页面更改其大小(由于新控件而扩大其宽度)时,对话框不调整大小,以便切断页面。 那么,如何根据页面调整对话框的大小?

I am creating a JFace WizardDialog including a single WizardPage that is changing its contents (controls) depending on user selection. In short:

final PageAccess page = new PageAccess(...);

WizCreate wiz = new WizCreate() {
    @Override
    public boolean performFinish() {
        page.performFinish();
        return true;
    }
};
wiz.addPage(page);

Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
WizardDialog dialog = new WizardDialog(shell, wiz);
dialog.open();

PageAccess extends WizardPage, and WizCreate extends Wizard.

All the Composites in the page use GridLayout.
The page implements a SelectionListener and redraws its contents.
When the page changes its size (expand its width because of new controls), the dialog is not resized so that the page is cut off.
So how to resize the dialog depending on the page?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

Spring初心 2025-02-17 05:02:45

wizardDialog实现iwizardContainer2具有更新方法,您可以调用该方法以重新计算大小。

在您的页面中,您可以使用

if (getContainer() instanceof IWizardContainer2 container) {
   container.updateSize();
} 

(代码使用Java 16 Instance Of类型模式,对于较旧的版本,它将更加复杂)。

请注意,WizardDialog只会增加大小,不会降低大小。

WizardDialog implements IWizardContainer2 which has an updateSize method that you can call to recalculate the size.

In your page you can use

if (getContainer() instanceof IWizardContainer2 container) {
   container.updateSize();
} 

(code uses Java 16 instanceof type patterns, for older releases it would be a bit more complicated).

Note that WizardDialog only ever increases the size, it won't reduce the size.

栖迟 2025-02-17 05:02:45

我通过计算主要控件的首选大小,然后调整对话框外壳的管理:

    Point preferredSize = getControl().computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
        
    WizardDialog dialog = (WizardDialog) getContainer();
    dialog.getShell().setSize(preferredSize.x+..., preferredSize.y+...);

I managed by calculating the preferred size of the main control, and then resizing the dialog shell:

    Point preferredSize = getControl().computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
        
    WizardDialog dialog = (WizardDialog) getContainer();
    dialog.getShell().setSize(preferredSize.x+..., preferredSize.y+...);
删除会话 2025-02-17 05:02:45

作为格雷格评论的后续,完整的解决方案是:

@Override
protected Point getInitialSize() {
    updateSize();
    return super.getInitialSize();
}

As a follow up to Greg comment, the full solution is:

@Override
protected Point getInitialSize() {
    updateSize();
    return super.getInitialSize();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文