Java 如何在另一个包含表查看器的组合顶部显示组合?

Java 如何在另一个包含表查看器的组合顶部显示组合?,java,eclipse,eclipse-plugin,swt,jface,Java,Eclipse,Eclipse Plugin,Swt,Jface,在向导页面的createControl(parent)方法中,代码如下所示- top = new Composite(parent, SWT.NONE); top.setLayout(new FillLayout()); setControl(top); setPageComplete(false); createViewer(top); 我想在由top表示的组合上方添加一行 它不允许我。如果我添加它,由top表示的composite将丢失 下面是为顶部

向导
页面的
createControl(parent)
方法中,代码如下所示-

    top = new Composite(parent, SWT.NONE);
    top.setLayout(new FillLayout());
    setControl(top);
    setPageComplete(false);
    createViewer(top);
我想在由
top
表示的组合上方添加一行

它不允许我。如果我添加它,由
top
表示的
composite
将丢失

下面是为顶部合成渲染的-

当我将下面的代码放在
top
组合之前时,
top
组合就丢失了-

    upper = new Composite(parent, SWT.NONE);
    upper.setLayout(new FillLayout());
    setControl(upper);
    Label label = new Label(page, SWT.NONE);
    label.setText("Some text to disply");
请就如何实现这一目标提出建议


下面是我的
createControl
代码片段。如果添加行,则会中断表格查看器的滚动和大小

@Override
public void createControl(Composite parent) {

    /*top = new Composite(parent, SWT.NONE);
    top.setLayout(new FillLayout());
    setControl(top);*/
    setPageComplete(false);

    top = new Composite(parent, SWT.NONE);
    top.setLayout(new GridLayout());
    setControl(top);

    Label label = new Label(top, SWT.NONE);
    label.setText("Some text to disply");
    label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));


    createViewer(top);
}

private void createViewer(Composite parent) {

    tableLayout = new TableColumnLayout();

    // A separate composite containing just the table viewer is required
    Composite tableComp = new Composite(parent, SWT.NONE);

    tableComp.setLayout(tableLayout);
    viewer = new TableViewer(tableComp, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    createColumns(parent, viewer);
    final Table table = viewer.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    viewer.setContentProvider(new ArrayContentProvider());

    // Layout the viewer
    GridData gridData = new GridData();
    gridData.verticalAlignment = GridData.FILL;
    gridData.horizontalSpan = 2;
    gridData.grabExcessHorizontalSpace = true;
    gridData.grabExcessVerticalSpace = true;
    gridData.horizontalAlignment = GridData.FILL;
    viewer.getControl().setLayoutData(gridData);
}

public TableViewer getViewer() {
    return viewer;
}



向导页只能有一个顶级组合。可以向该组合添加多个控件(包括嵌套组合)

因此,对于上表中的标签:

top = new Composite(parent, SWT.NONE);
top.setLayout(new GridLayout());
setControl(top);

Label label = new Label(top, SWT.NONE);
label.setText("Some text to disply");
label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));

TableViewer viewer = new TableViewer(top, .... flags
viewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

@greg-449:我想在表格查看器的下方或上方显示一些文本。有什么办法吗?您只需将多个控件添加到顶级组合中。这可能包括嵌套复合材料。您可能需要使用不同的布局—例如GridLayout。它仍然会中断。表格查看器的滚动消失。我已经附上了同样的代码片段。您显示的代码没有试图在表上方放置标签-那么它与答案有什么关系?您需要在
tableComp
上设置GridData,查看器控件不应该有GridData,因为TableColumnLayout处理这个问题<代码>表格组件setLayoutData(新网格数据(SWT.FILL,SWT.FILL,true,true))
TableColumnLayout
和对
setColumnData
的调用将无效,并且不会显示我的整个表。我在问题中添加了代码,但事实并非如此
tableComp.setLayoutData
设置
tableComp
的父组合使用的布局数据。TableColumnLayout显示tableComp的子级。
top = new Composite(parent, SWT.NONE);
top.setLayout(new GridLayout());
setControl(top);

Label label = new Label(top, SWT.NONE);
label.setText("Some text to disply");
label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));

TableViewer viewer = new TableViewer(top, .... flags
viewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));