我是 eclipse 插件的新手 - SWT 开发。我正在尝试创建具有多个文本字段和组合框的向导页面。为了更好的外观和感觉,我正在尝试使用FormToolkit
创建组件并将它们添加到ScrolledForm
. 但是,在运行时向导页面上不会呈现任何内容,也没有错误。问题:
- 是否可以在向导页面内滚动容器?
我们可以混合使用 JFace 和 forms api 吗? (删除不需要的代码) 这是向导页面代码:
公共类 ContactWizardPage 扩展 WizardPage { 私有静态 int 计数器;私人表格;
public ContactWizardPage() { super("New Contact Wizard" + ++counter, "New Contact Wizard" + counter, null); setMessage("Please enter contact info." + counter); } public void createControl(final Composite parent) { createControlWithoutToolkit(parent); // commenting out toolkit code
// createControlWithToolkit(parent); }
public void createControlWithoutToolkit(final Composite parent) { Composite composite = new Composite(parent, SWT.DEFAULT); composite.setLayout(new GridLayout(2, true)); Label lblFirstName = new Label(composite, SWT.FLAT); lblFirstName.setText("First Name"); Label lblLastName = new Label(composite, SWT.FLAT); lblLastName.setText("Last Name"); Text txtFirstName = new Text(composite, SWT.FLAT); Text txtLastName = new Text(composite, SWT.FLAT); Label lblEmail = new Label(composite, SWT.FLAT); lblEmail.setText("Email"); GridDataFactory.swtDefaults().span(2, 1).align( SWT.FILL, SWT.BEGINNING).applyTo(lblEmail); Text txtEmail = new Text(composite, SWT.FLAT); GridDataFactory.swtDefaults().span(2, 1).align( SWT.FILL, SWT.BEGINNING).applyTo(txtEmail); setControl(composite); } public void createControlWithToolkit(final Composite parent) { FormToolkit toolkit = new FormToolkit(Display.getCurrent()); ScrolledForm form = toolkit.createScrolledForm(parent); Composite composite = form.getBody(); composite.setLayout(new GridLayout(2, true)); Label lblFirstName = toolkit.createLabel(composite, "First Name"); Label lblLastName = toolkit.createLabel(composite, "Last Name"); Text txtFirstName = toolkit.createText(composite, ""); Text txtLastName = toolkit.createText(composite, ""); Label lblEmail = toolkit.createLabel(composite, "Email"); GridDataFactory.swtDefaults().span(2, 1).align( SWT.FILL, SWT.BEGINNING).applyTo(lblEmail); Text txtEmail = toolkit.createText(composite, ""); GridDataFactory.swtDefaults().span(2, 1).align( SWT.FILL, SWT.BEGINNING).applyTo(txtEmail); setControl(composite); }
}
这是向导代码:
public class SampleNewWizard extends Wizard implements INewWizard {
public SampleNewWizard() {
super();
setNeedsProgressMonitor(true);
}
@Override
public IWizardPage getNextPage(IWizardPage page) {
return super.getNextPage(page);
}
public void addPages() {
addPage(new ContactWizardPage());
addPage(new ContactWizardPage());
addPage(new ContactWizardPage());
addPage(new ContactWizardPage());
}
public boolean performFinish() {
return true;
}
public void init(IWorkbench workbench, IStructuredSelection selection) {
}
}
使用此代码,向导的第一页显示正常,但第二页永远无法正确呈现。:(这里是截图:第一页:
第二页: