我创建了一个包含一个页面的向导,它有两个小部件:一个列表和一个按钮
但是当使用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;
}
}
答案 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)
您需要为Composite设置布局。 有关使用GridLayout的示例,请参阅 - https://www.eclipse.org/swt/snippets/#gridlayout
有关在WizardPage中使用GridLayout的示例,请参阅 - http://git.eclipse.org/c/platform/eclipse.platform.ui.git/tree/examples/org.eclipse.jface.snippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippets/wizard/Snippet047WizardWithLongRunningOperation.java