resizejface

How to resize a WizardDialog depending on the WizardPage?


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?


Solution

  • 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+...);