gpt4 book ai didi

java - 使用向导和 ScrolledForm(jface 和 forms api)

转载 作者:行者123 更新时间:2023-12-01 14:07:46 24 4
gpt4 key购买 nike

我是 eclipse 插件 - SWT 开发的新手。我正在尝试创建具有多个文本字段和组合框的向导页面。为了更好的外观和感觉,我尝试使用 FormToolkit 创建组件并将它们添加到 ScrolledForm 中。但是这样在运行时向导页面上不会呈现任何内容,也不会出现错误。问题:

  1. 向导页面内是否可以有滚动容器?
  2. 我们可以混合使用 JFace 和 forms api 吗?(删除了不需要的代码)这是向导页面代码:

    公共(public)类ContactWizardPage扩展WizardPage { 私有(private)静态 int 计数器; 私有(private)表格;

    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) {

}

}

使用此代码,向导的第一页显示正常,但第二页永远无法正确呈现。 :(这是截图:第一页:

enter image description here

第二页: enter image description here

最佳答案

线路

parent.getShell().setSize(240, 320);                    

令人不安(并且不是您应该在向导页面中执行的操作,因为 Wizard 类处理大小调整)。在这里测试,没有它它工作正常(我得到了你的问题)。

关于java - 使用向导和 ScrolledForm(jface 和 forms api),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18762211/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com