Java 无法调整SWT组件的大小(TextMergeViewer)

Java 无法调整SWT组件的大小(TextMergeViewer),java,eclipse,eclipse-plugin,swt,Java,Eclipse,Eclipse Plugin,Swt,我的问题是:我一直在使用SWT为Eclise插件构建一个小GUI。在下图中,零件1,2,2',3,3'的行为完全符合我的要求,并正确安装在窗口中 但是,第四部分(TextMergeViewer)在其容器的角落中保持较小的大小 例如,下面的代码显示了我是如何定义第2部分和第2部分的: Composite viewersContainer; viewersContainer = new Composite(shell, SWT.BORDER); viewersContain

我的问题是:我一直在使用SWT为Eclise插件构建一个小GUI。在下图中,零件1,2,2',3,3'的行为完全符合我的要求,并正确安装在窗口中

但是,第四部分(TextMergeViewer)在其容器的角落中保持较小的大小

例如,下面的代码显示了我是如何定义第2部分和第2部分的:

    Composite viewersContainer;
    viewersContainer = new Composite(shell, SWT.BORDER);
    viewersContainer.setLayout(new GridLayout(2, false));
    viewersContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    data = new GridData(SWT.FILL, SWT.FILL, true, true);
    data.heightHint = 400;
    data.widthHint = 400;

    oldFileViewer = new Browser(viewersContainer, SWT.BORDER);
    oldFileViewer.setText("here is the old file viewer\t\t\t\t\t\t\t\t\t\n\n\n\n\n\n");
    oldFileViewer.setLayoutData(data);

    newFileViewer = new Browser(viewersContainer, SWT.BORDER);
    newFileViewer.setText("and here is the new file viewer\t\t\t\t\t\t\t\t\t\n\n\n\n\n\n");
    newFileViewer.setLayoutData(data);
在创建第四部分时,我尝试使用以下代码保留该模型:

    Composite c = new Composite(shell, SWT.BORDER);
    c.setLayout(new GridLayout(1, false));
    GridData l = new GridData(SWT.FILL, SWT.FILL, false, false);
    c.setLayoutData(l);

    TextMergeViewerCreator tmvc = new TextMergeViewerCreator();

    TextMergeViewer tmv = null;

    tmv = (TextMergeViewer) tmvc.createViewer(c, new CompareConfiguration());


    DiffNode d = null;
    try {
        d = (DiffNode) (new CompareInput().prepareInput(new IProgressMonitor() {
            //Some overrided methods

            }
        }));
    } catch (InvocationTargetException | InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    d.setDontExpand(false);
    tmv.setInput(d);
我猜DiffNode不对TextMergeViewer文件负责,但我无法找到代码中的错误。 任何帮助都将不胜感激!
感谢阅读。

您需要在
TextMergeViewer
控件中设置
GridData

tmv.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

另外,请注意:不要重用
GridData
对象。每个小部件都应该有自己的
GridData

:

注意:不要重用GridData对象。由GridLayout管理的组合中的每个控件都必须具有唯一的GridData对象


TextMergeViewer似乎没有
setLayoutData
method@MedAl尝试在
getControl()的结果上调用它