SWT: nested layouts with ScrolledComposite exceed available space

I want to create a Master-Detail layout for one of my applications using SWT.

The container, contents, sidebar, and part 1 are composite instances. Scrolling is a ScrolledComposite

The desired layout is something like:

+--Container-------------------------------------+
|+--Content----------------------++--Sidebar----+|
||                               ||+--Part1----+||
||                               |||           |||
||                               |||           |||
||                               |||           |||
||                               |||           |||
||                               |||           |||
||                               ||+-----------+||
||                               ||+--Scrolled-+||
||                               |||           |||
||                               |||           |||
||                               |||           |||
||                               |||           |||
||                               |||           |||
||                               ||+-----------+||
|+-------------------------------++-------------+|
+------------------------------------------------+

Content should capture the entire horizontal and vertical space that is available.

The sidebar is basically a container for part 1 and scroll, which should be the same height.

Scrolling is a container for a composite containing a dynamic number of auxiliary elements that are located in the composition of the content. Since there can be a large change in the number of subitems, this Composite should be scrollable.

:

  • GridLayout 2- .

  • FILL_BOTH HORIZONTAL/VERTICAL.

  • FillLayout (SWT.VERTICAL) Part1 Scrolled Childs.

: , , , .

FillLayout (SWT.HORIZONTAL) , , , " ".

GridLayout, , .

SWT-:

public class Scrolled {
    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setLayout(new GridLayout(2,false));
        //shell.setLayout(new FillLayout(SWT.HORIZONTAL));

        Composite content = new Composite(shell, SWT.BORDER);
        content.setLayoutData(new GridData(SWT.LEFT,SWT.CENTER,false,false));

        Composite sidebar = new Composite(shell, SWT.BORDER);
        sidebar.setLayout(new FillLayout(SWT.VERTICAL));
        sidebar.setLayoutData(new GridData(SWT.LEFT,SWT.CENTER,false,false));

        Composite cc = new Composite(sidebar, SWT.BORDER);

        ScrolledComposite sc = new ScrolledComposite(sidebar, SWT.BORDER
                | SWT.V_SCROLL | SWT.H_SCROLL);
        sc.setLayout(new GridLayout(1,true));

        Composite c = new Composite(sc, SWT.NONE);
        c.setSize(400, 400);
        c.setLayout(new GridLayout(1, true));

        for(int i = 0; i < 1000; i++){
            new Button(c, SWT.PUSH).setText("Text");
        }

        sc.setMinSize(c.computeSize(SWT.DEFAULT, SWT.DEFAULT));
        sc.setContent(c);
        sc.setExpandHorizontal(true);
        sc.setExpandVertical(true);
        sc.setAlwaysShowScrollBars(true);

        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
    }
}
+5
1

, .

, Composite GRAB_EXCESS_VERTICAL . , .

:

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

sidebar.setLayoutData(new GridData(SWT.FILL,SWT.FILL,false,true));
+5

All Articles