I have the following SWT layout:
- TabItem
- SashForm
- Composite (GridLayout)
- Label (Fill W, Grab H)
- ScrolledComposite (Fill W/H, Grab H/V)
- Composite (RowLayout)
- Composite (GridLayout)
- Label (Fill W, Grab H)
- ScrolledComosite (Fill W/H, Grab H/V)
- Composite (RowLayout)
- Composite (GridLayout)
- SashForm
The general idea is that there are two identical panes side-by-side with adjustable widths via the sash, and inside each panel is a label at the top, and a scrolled composite on the bottom. The scrolled composite will have many (1 – 50) 100×100 composites contained within the wrapped composite.
The problem is that when contained within a sash form, the scrolled composites will not scroll when the internal composite grows due to a large number of children. I do not experience this problem when I abandon the SashForm and use a regular Composite, like so:
- TabItem
- Composite (GridLayout)
- Label
- ScrolledComposite
- Composite
- Label
- ScrolledComposite
- Composite
- Composite (GridLayout)
In this way, there is no extra composite container, and everything is in a grid layout. The only problem is that I can’t adjust the width of the panes via a common interface (sash).
I have tried forcing layout using layout(), and setting the minimum size using setMinSize(). I tried swapping RowLayout with a FlowLayout (swing2swt). I am assuming this is a type of layout problem, but I do not have enough SWT experience to sort it out. The layout is perfect except for the scrolling problem.
Source Example
All of the code was auto-generated by WindowBuilder Pro, and can be replicated by building the composite tree I specified. Here is a fragment I am using to populate the wrapped composite:
public void populate(Composite composite, List<Photo> items) {
composite.setRedraw(false);
for (Photo photo : photos) {
PhotoComposite composite = new PhotoComposite(composite, photo, SWT.NONE);
composite.setSize(100, 100);
}
composite.setRedraw(true);
composite.layout(true);
}
Photo is a simple POJO, and PhotoComposite is a custom composite that takes a Photo as a parameter in the constructor in addition to the traditional Composite and style bits. This code appears to work fine according to my experiments.
It turns out the problem was a misunderstanding of
setMinSize(int, int). The following changes to the populate method shown above solved the problem for me: