我在编辑器中使用 TableWrapLayout
并排排列了两个部分。正如您在下面的屏幕截图中所见,右侧部分的标题未使用全宽。展开时,该部分的标题和内容均使用完整宽度。当该部分再次关闭时,它会保持这种状态。所以这个问题只有在打开编辑器时才会出现。
那么,如何让 section 部分使用全宽呢?
我已经将 TableWrapData 的 grabHorizontal
属性设置为 true
并在底层复合 Material 上使用了 GridData.FILL_HORIZONTAL
。
当然,将部分设置为立即展开可以解决问题,但我想一开始就保持关闭状态,因为加载该部分的内容会做一些繁重的后端工作,因此会导致更长的加载时间编辑。
编辑器代码:
public void createPartControl(Composite parent) {
toolkit = new FormToolkit(parent.getDisplay());
form = toolkit.createScrolledForm(parent);
form.setLayoutData(new GridData(GridData.FILL_BOTH));
toolkit.decorateFormHeading(form.getForm());
TableWrapLayout layout = new TableWrapLayout();
layout.numColumns = 2;
form.getBody().setLayout(layout);
createMetaInfoSection();
createUpdateDocumentSection();
}
private void createMetaInfoSection() {
Section metaInfoSection = toolkit.createSection(form.getBody(), Section.DESCRIPTION | Section.TITLE_BAR | Section.TWISTIE | Section.EXPANDED);
TableWrapData twd = new TableWrapData();
twd.grabHorizontal = true;
twd.colspan = 1;
metaInfoSection.setLayoutData(twd);
// Composite
Composite composite = toolkit.createComposite(metaInfoSection);
GridLayout gridLayout = new GridLayout();
composite.setLayout(gridLayout);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
// Content
...
metaInfoSection.setClient(composite);
}
private void createUpdateDocumentSection() {
Section updateDocumentSection = toolkit.createSection(form.getBody(), Section.DESCRIPTION | Section.TITLE_BAR | Section.TWISTIE | Section.EXPANDED);
TableWrapData twd = new TableWrapData();
twd.grabHorizontal = true;
twd.colspan = 1;
updateDocumentSection.setLayoutData(twd);
// Composite
Composite composite = toolkit.createComposite(updateDocumentSection);
GridLayout gridLayout = new GridLayout();
composite.setLayout(gridLayout);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
// Content
...
updateDocumentSection.setClient(composite);
}
最佳答案
试试这个
TableWrapData twd = new TableWrapData(TableWrapData.FILL_GRAB);
关于java - eclipse 用户界面 : Section heading in a TableWrapLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12040211/