java - eclipse 用户界面 : Section heading in a TableWrapLayout

标签 java layout swt eclipse-rcp jface

我在编辑器中使用 TableWrapLayout 并排排列了两个部分。正如您在下面的屏幕截图中所见,右侧部分的标题未使用全宽。展开时,该部分的标题和内容均使用完整宽度。当该部分再次关闭时,它会保持这种状态。所以这个问题只有在打开编辑器时才会出现。

那么,如何让 section 部分使用全宽呢? 我已经将 TableWrapData 的 grabHorizo​​ntal 属性设置为 true 并在底层复合 Material 上使用了 GridData.FILL_HORIZONTAL

当然,将部分设置为立即展开可以解决问题,但我想一开始就保持关闭状态,因为加载该部分的内容会做一些繁重的后端工作,因此会导致更长的加载时间编辑。

Editor

编辑器代码:

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/

相关文章:

java - Java 中的 'system default package' 是什么?

CSS 布局,不同的列宽

java - 如何给自定义控件添加监听器?

java - 如果操作不是由用户触发的,如何禁用 SWT 事件监听

java - JSTL 对象位于 url 中,而不是标记上下文中

java - Netbeans - 应用程序重新启动

java - 无法在 Java 正则表达式中使用 '-' 字符,它在给定文本中找不到模式

jquery - 从 Google API 将背景图片附加到超大屏幕类

css - 表格显示的表格标签不好......但是调查问题怎么样?

java - JFace TreeViewer,当某些空文件夹被填充时如何通知树