Java ScrolledComposite:需要时滚动条不显示

Java ScrolledComposite:需要时滚动条不显示,java,swt,composite,scrolledcomposite,Java,Swt,Composite,Scrolledcomposite,我有一个UI,如下所示 我在这里试图做的是在开始时初始化整个UI,并在用户填写一些输入时调用relayat方法。这里的问题是,如果我的内容(此处的名称)占用更多空间,那么滚动条应该显示出来,让用户滚动,以便他们可以看到数据,但滚动条根本不显示 protected void initializeFrame() { setLayout(new FillLayout()); mainComposite = new Composite(this, SWT.NONE); main

我有一个UI,如下所示

我在这里试图做的是在开始时初始化整个UI,并在用户填写一些输入时调用relayat方法。这里的问题是,如果我的内容(此处的名称)占用更多空间,那么滚动条应该显示出来,让用户滚动,以便他们可以看到数据,但滚动条根本不显示

protected void initializeFrame() {
    setLayout(new FillLayout());

    mainComposite = new Composite(this, SWT.NONE);
    mainComposite.setBackground(getBackground());
    GridLayout layout = new GridLayout(2, false);
    mainComposite.setLayout(layout);

    GridData data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.grabExcessHorizontalSpace = true;
    data.horizontalSpan = 2;
    headingComposite = new Composite(mainComposite, SWT.BORDER);
    headingComposite.setBackground(getBackground());
    headingComposite.setLayoutData(data);

    scrolledComposite = new ScrolledComposite(mainComposite, SWT.V_SCROLL| SWT.H_SCROLL);
    scrolledComposite.getVerticalBar().setIncrement(10);
    scrolledComposite.getVerticalBar().setPageIncrement(100);
    scrolledComposite.getHorizontalBar().setIncrement(10);
    scrolledComposite.getHorizontalBar().setPageIncrement(100);
    scrolledComposite.setExpandHorizontal(true);
    scrolledComposite.setExpandVertical(true);

    data = new GridData(GridData.FILL_BOTH );
    data.widthHint = 500;
    scrolledComposite.setLayoutData(data);

    leftEditorComposite = new Composite(scrolledComposite, SWT.BORDER);
    leftEditorComposite.setBackground(getBackground());  
    scrolledComposite.setContent(leftEditorComposite);

    data = new GridData(GridData.FILL_BOTH);
    data.widthHint = 150;
    rightEditorComposite = new Composite(mainComposite, SWT.BORDER);
    rightEditorComposite.setBackground(getBackground());
    rightEditorComposite.setLayoutData(data);
}

public void relayout() {
    scrolledComposite.setMinSize(leftEditorComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
}

谁能告诉我这里怎么了

什么时候重播?您需要在初始化期间执行setMinSize。我想我没有在初始化期间设置它,但仅在内容更改时设置。在初始化过程中应该如何设置它?谢谢!我认为在初始化期间也不必调用setMinSize。它通常在SelectionListener或SelectionAdapter中调用。但是,我在GridLayout中找不到具有父级的ScrolledComposite的工作示例。我认为这是你最可能遇到的问题。除非你同时找到了解决办法。在这种情况下,请大家在这里分享答案!