我在eclipse rcp中的对话框中遇到了一些麻烦。我希望有一个对话框向我展示一个MasterDetailBlock,用于管理主部件中表格中显示的任意数量的实体,以及其详细部分中显示的相应DetailPages。到目前为止,这是使用视图完成的,但非模态对话似乎更适合于此。Eclipse RCP:控件在对话框中不可见
起初,我尝试了从视图中取代码并将其放入对话框的一种天真的方式,由于视图和对话框创建之间的差异而进行了一些修改。但是,大部分控制都失踪了。在Google,eclipse论坛和Stackoverflow上的搜索没有为此提供解决方案。在检查这些网站的解决方案之后,我尝试通过调试器逐步了解代码来了解发生了什么,但这也没有帮助我。
下面的代码应该显示一个对话框,其中应该显示一个按钮部分。然而,它并不:
protected Control createDialogArea(Composite parent) {
parent.setLayout(new GridLayout(1, true));
Section section = toolkit.createSection(parent, ExpandableComposite.EXPANDED | ExpandableComposite.TITLE_BAR);
section.setLayout(new GridLayout());
section.setText("Section");
section.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
Button test = toolkit.createButton(section, "test", SWT.PUSH);
test.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
test.setVisible(true);
section.computeSize(SWT.DEFAULT, SWT.DEFAULT);
return parent;
}
这样做的结果是:
但是,作为一个MasterDetailBlock需要一个形式,我将提供本准则以及:
protected Control createDialogArea(Composite parent) {
parent.setLayout(new GridLayout(1, true));
form = new ScrolledForm(parent);
form.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
form.getBody().setLayout(new FillLayout());
Composite formComposite = toolkit.createComposite(form.getBody());
formComposite.setLayout(new GridLayout(1,true));
Section section = toolkit.createSection(formComposite, ExpandableComposite.EXPANDED | ExpandableComposite.TITLE_BAR);
section.setLayout(new GridLayout());
section.setText("Section");
section.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
Button test = toolkit.createButton(section, "test", SWT.PUSH);
test.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
test.setVisible(true);
section.computeSize(SWT.DEFAULT, SWT.DEFAULT);
return parent;
}
只需稍加修改即可在对话框中添加窗体,窗体上的任何内容都会显示出来。但是,结果是这样的:
我怕我失去了的东西在这里很明显。正如我所说的,搜索没有带来任何启发,并且通过代码也没有帮助。我最后的手段“试着看看会发生什么并试图理解这一点”并没有多大帮助,因为结果与已发布的结果没有什么不同。
那么,我错过了什么吗? (我认为是这样) 如果你可以提供给我一个链接,告诉我什么是错的(或者你的经验也是如此),我会说服你。
谢谢你的帮助。
谢谢你的回答,我怀疑这会很简单。尽管如此,我很抱歉,通常我会更快。 – Shelling 2013-03-18 21:59:18