Reputation: 71
How can I set height and scroll for Group
? drawWitness
in the below code, returns a shape. It is not completely in the group with the below code. What should I do?
composite = (Composite) super.createDialogArea(parent);
composite.setLayout(new GridLayout());
GridData data = new GridData(GridData.FILL_HORIZONTAL);
Group grpModelProperties = new Group(composite, SWT.SHADOW_IN);
grpModelProperties.setLayout(new GridLayout(2, false));
grpModelProperties.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
Label l1 = new Label(grpModelProperties, SWT.NULL);
new Label(grpModelProperties, SWT.NONE);
Label l2 = new Label(grpModelProperties, SWT.NULL);
new Label(grpModelProperties, SWT.NONE);
Label l3 = new Label(grpModelProperties, SWT.NULL);
l1.setLayoutData(data);
l1.setText("Some Text1");
l2.setLayoutData(data);
l2.setText("Some Text2");
l2.setSize( 470, 400 );
Label line = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL );
line.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
scrolledComposite = new ScrolledComposite( composite, SWT.H_SCROLL | SWT.V_SCROLL );
grpModelProperties1 = new Group(scrolledComposite, SWT.SHADOW_IN);
grpModelProperties1.setLayout(new GridLayout(1, false));
GridData data1 = new GridData(SWT.FILL, SWT.TOP, true, false);
data1.heightHint = 150;
grpModelProperties1.setLayoutData(data1);
grpModelProperties1.setText("Test Model");
drawWitness(model);
scrolledComposite.addListener( SWT.Resize, event -> {
int width = scrolledComposite.getClientArea().width;
scrolledComposite.setMinSize( composite.computeSize( width, SWT.DEFAULT ) );
} );
Upvotes: 1
Views: 821
Reputation: 111142
Set the width and height hints for the layout data of the group:
GridData data = new GridData(SWT.FILL, SWT.TOP, true, false);
data.widthHint = 200;
data.heightHint = 200;
grpModelProperties1.setLayoutData(data);
To use ScrolledComposite
you need something like:
ScrolledComposite scrolledComposite = new ScrolledComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL);
// You must set a layout on scrolled composite
scrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
scrolledComposite.setExpandHorizontal(true);
scrolledComposite.setExpandVertical(true);
// Additional inner composite is required
Composite innerComposite = new Composite(scrolledComposite, SWT.NONE);
innerComposite.setLayout(new GridLayout());
Group grpModelProperties1 = new Group(innerComposite, SWT.SHADOW_IN);
grpModelProperties1.setLayout(new GridLayout());
grpModelProperties1.setText("Test Model");
GridData data1 = new GridData(SWT.FILL, SWT.TOP, true, false);
data1.heightHint = 400;
data1.widthHint = 400;
grpModelProperties1.setLayoutData(data1);
scrolledComposite.setContent(innerComposite);
// No need to use a resize listener
scrolledComposite.setMinSize(innerComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
Upvotes: 3