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.
:
:
, , , .
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));
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();
}
}