Reputation: 21
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?
Upvotes: 0
Views: 122
Reputation: 1
As a follow up to Greg comment, the full solution is:
@Override
protected Point getInitialSize() {
updateSize();
return super.getInitialSize();
}
Upvotes: 0
Reputation: 21
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+...);
Upvotes: 0
Reputation: 111216
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.
Upvotes: 1