|
Re: Min size of a component? layout question [message #556912 is a reply to message #556705] |
Fri, 03 September 2010 07:06 |
|
Lakshmi P Shanmugam Messages: 279 Registered: July 2009 Location: India |
Senior Member |
|
|
Hi,
You can use the ScrolledComposite methods, setMinSize , setMinHeight or setMinWidth to do this. You can recompute and reset the minSize based on the number of controls that have to be displayed.
Here is a small example:
public class ScrolledCompositeExample {
public static void main(String[] args) {
final int MIN_HEIGHT = 100;
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
Button button = new Button(shell, SWT.PUSH);
button.setText("add another button");
final ScrolledComposite sc = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL);
final Composite childComposite = new Composite(sc, SWT.NONE);
childComposite.setLayout(new FillLayout(SWT.VERTICAL));
new Button(childComposite, SWT.PUSH | SWT.BORDER).setText("button");
sc.setContent(childComposite);
sc.setMinSize(300, MIN_HEIGHT);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
new Button(childComposite, SWT.PUSH | SWT.BORDER).setText("button");
int height = childComposite.getChildren().length * MIN_HEIGHT;
sc.setMinHeight(height);
childComposite.layout(false);
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
Lakshmi P Shanmugam
[Updated on: Fri, 03 September 2010 07:07] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03180 seconds