我在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