ScrolledComposite:需要时不显示滚动条

时间:2014-03-21 23:25:35

标签: java swt composite scrolledcomposite

我有一个如下所示的用户界面。

enter image description here

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

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));
}

谁能告诉我这里有什么问题?

0 个答案:

没有答案