1

I have a UI which looks like below.

enter image description here

What I'm trying to do here is I initialize the whole UI in the beginning and call the relayout() method whenever the user has filled some input. The problem here is, if my content (the "name" here) takes more spaces, then the scroll bar is supposed to show up and let user scroll so that they can see the data, but the scroll bar doesn't show up at all.

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

Can anyone tell me what is wrong here?

Rüdiger Herrmann
  • 20,512
  • 11
  • 62
  • 79
huao
  • 554
  • 1
  • 5
  • 22
  • When is `relayout` called? You need to do the `setMinSize` during the initialization. – greg-449 Mar 22 '14 at 08:07
  • I dont think I've set it during the initialization, but only whenever the content is changed. How should I set it during initialization? thanks a lot! – huao Mar 25 '14 at 17:27
  • I don't think `setMinSize` has to be called during initialization either. It is usually called in the `SelectionListener` (or `SelectionAdapter` rather). However, I couldn't find a working example for a `ScrolledComposite` with a parent in `GridLayout`. I think that's your most likely problem. Unless you have found a solution in the meantime. In this case, please (pretty please actually) share as an answer here! – s.d Apr 07 '16 at 06:56

0 Answers0