0

I am trying to have a scrolled composite with a fixed size content and a label below the scrolled composite display status information of the scrollable content. As I want the controls to resize with the parent, I have used GridLayout on their parent. But I am facing an issue with the scroll bars of the scrolled composite and positioning of the label control. i.e, the scrolling doesn't work unless I set the scrolledcomposite's grid data attribute as

grabExcessVerticalspace = true

If I allow the scrolledcomposite to grab the excess vertical space, the label does not appear below the scrolledcomposite due to the space between them.

public class Snippet5 {

  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new GridLayout(1, true));

    // this button is always 400 x 400. Scrollbars appear if the window is
    // resized to be too small to show part of the button
    ScrolledComposite c1 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    Button b1 = new Button(c1, SWT.PUSH);
    b1.setText("fixed size button");
    b1.setSize(400, 400);
    c1.setAlwaysShowScrollBars(true);
    c1.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, true));
    c1.setContent(b1);

    Label l = new Label(shell, SWT.BORDER);
    l.setText("button clicked");
    GridData layoutData = new GridData(SWT.LEFT, SWT.TOP, true, false);
    layoutData.heightHint = 30;
    layoutData.widthHint  = 400;
    l.setLayoutData(layoutData);

    shell.setSize(600, 300);
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }
    display.dispose();
  }
}

Any help in having the label appear exactly below the scrolled composite (trim the space) and have the scrolling work is appreciated.

Edit:

Expected behavior:

  1. Extra vertical space to be grabbed by the label.
  2. The scrolledcomposite should enable vertical scrolling when the content cannot be viewed completely when the shell is re-sized.

enter image description here

Monikka
  • 518
  • 6
  • 12

1 Answers1

0

You need to set the layout data of the ScrolledComposite to FILL like so:

new GridData( SWT.FILL, SWT.FILL, true, true );

This way, the ScrolledComposite will take the available space of the grid cell.

Rüdiger Herrmann
  • 20,512
  • 11
  • 62
  • 79
  • This causes the extra space to be added below the content being scrolled instead of being shown between the scrolled composite and label as before. I want the scrolled composite to wrap the content followed by the label with no extra space between any of the controls. This can be achieved by setting the grabExcessVerticalSpace to FALSE but then the vertical scrolling does not work. – Monikka Sep 13 '16 at 08:59
  • 1
    Please clarify your question: where should the extra space be? the scrolled composite should not be any later than its content? – Rüdiger Herrmann Sep 13 '16 at 13:47
  • I would like the label to grab the excess vertical space. i.e, scrolledcomposite's grabverticalspace = false. But then the scrolling doesn't work. So I trying to figure out a way for the scrolling to work and have no spacing between the composite and label. I have edited the question, please let me know if the edit is clear. – Monikka Sep 14 '16 at 06:50