打开对话框时,向导中不显示SWT窗口小部件

时间:2015-11-12 04:55:28

标签: java swt wizard

我创建了一个包含一个页面的向导,它有两个小部件:一个列表和一个按钮 但是当使用dialog.open()调用向导时,向导会打开,但不会显示页面的小部件。我不知道出了什么问题!

以下是页面的代码

public class SelectCriterionPage extends WizardPage  {

private Composite container;
ArrayList<String> listItems=new ArrayList<String>();
List variables,selected;
protected SelectCriterionPage() {

super("CriterionSelection","SelectCriterionPage",null);

setTitle("Selection of criterion variables");



}
@Override

public void createControl(Composite parent) {

container = new Composite(parent, SWT.NONE);
variables=new List(container, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
//fill the list with variables
for(String item:listItems)
variables.add(item);

variables.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {


}

@Override
public void widgetDefaultSelected(SelectionEvent e) {
        // TODO Auto-generated method stub

}
});
Button btn=new Button(container, SWT.PUSH);
btn.setText("<");
GridData gr=new GridData(GridData.FILL,SWT.CENTER);
btn.setLayoutData(gr);
setControl(container);

}
}

我打电话给我的巫师

WizardDialog dialog = new WizardDialog(null, new       SelectSlicingCriterionWizard());
dialog.open();

这是我的向导:

public class SelectSlicingCriterionWizard extends Wizard{
IWorkbenchPage workbench;
IStructuredSelection selection;
ArrayList<String> listItems;

 public SelectSlicingCriterionWizard() {

        super();

        setNeedsProgressMonitor(true);

      }


@Override
public boolean performFinish() {
    System.out.println("Finish clicked");
    return true;
}

@Override
public boolean performCancel(){
    return true;
}

 @Override

  public void addPages() {
     SelectCriterionPage criterionpage=new SelectCriterionPage();
     addPage(criterionpage);
 }
 @Override

  public String getWindowTitle() {

    return "Select Criterion Variables";

}
public void init(IWorkbench workbench, IStructuredSelection selection)
{
this.workbench=workbench.getActiveWorkbenchWindow().getActivePage();
this.selection=selection;
}
}

2 个答案:

答案 0 :(得分:2)

您尚未为向导页面Composite设置布局。因为您似乎正在尝试使用网格,所以应该是:

container = new Composite(parent, SWT.NONE);

container.setLayout(new GridLayout());

您的GridData按钮使用了错误的构造函数(两个参数构造函数设置高度和宽度)。使用类似的东西:

GridData gr = new GridData(SWT.BEGINNING, SWT.TOP, false, false);

btn.setLayoutData(gr);

答案 1 :(得分:1)