Composite composite = new Composite(parent, SWT.NONE); Text text = new Text(composite, SWT.NONE); Point size = text.computeSize(SWT.DEFAULT, SWT.DEFAULT); composite.setSize(size);
Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(new GridLayout(2, false)); Label label1 = new Label(composite, SWT.NONE); label1.setText("Label 1:"); Label label2 = new Label(composite, SWT.NONE); label2.setText("Label 2:"); Point size = composite.computeSize(200, SWT.DEFAULT); composite.setSize(size);This code creates a Composite with a GridLayout containing two Labels. It then computes the size of the Composite with a fixed width of 200 pixels and sets the size of the Composite accordingly. Package library: org.eclipse.swt.widgets is part of the SWT library, which is included in the Eclipse platform.