[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.tools] Re: Scrollable Composite for multipage editor
|
Here is an example that creates several widgets that are scrolled
vertically by a ScrolledComposite.
Note that as you said the ScrolledComposite can only scroll one widget so
I have created a composite to parent the multiple widgets that I wish to
scroll. This second composite lays the multiple widgets out for me.
The problem you are having about not seeing anything could be because you
have added a bunch of children and not told the parent to lay out again.
In the example below, shell.open() causes the children to be laid out by
the FillLayout which cascades the layout all the way down the widget tree.
If your shell is already open, you can get the same result be calling
"layout(true)" on your top widget. For more info on layouts see the
article "Understanding Layouts in SWT" posted on the Eclipse Corner website under articles.
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
ScrolledComposite scrollParent = new ScrolledComposite(shell, SWT.V_SCROLL);
Composite parent = new Composite(scrollParent, SWT.NONE);
scrollParent.setContent(parent);
parent.setLayout(new GridLayout());
Text t = new Text(parent, SWT.MULTI | SWT.BORDER);
t.setText("Text widget");
GridData data = new GridData(GridData.FILL_BOTH);
data.widthHint = 400;
data.heightHint = 400;
t.setLayoutData(data);
Button b = new Button(parent, SWT.PUSH);
b.setText("Button 1");
b = new Button(parent, SWT.PUSH);
b.setText("Button 2");
b = new Button(parent, SWT.PUSH);
b.setText("Button 3");
Point minSize = parent.computeSize(SWT.DEFAULT, SWT.DEFAULT);
scrollParent.setExpandVertical(true);
scrollParent.setMinWidth(minSize.x);
scrollParent.setExpandHorizontal(true);
scrollParent.setMinHeight(minSize.y);
shell.open();
while (shell != null && !shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}