Reputation: 1367
What is the difference between Group Control and Composite apart from the way they look? Can i place a container inside a Group? If yes, what Layout will I have to use? I tried placing a container inside a Group but the controls inside the Container did not show up.
Group grp= new Group(container, SWT.NONE);
grp.setText("XYZ");
grp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
Conatiner cnt = new Container(grp, SWT.NONE);
cnt.setLayout(new GridLayout(4,true));
cnt.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
Text text = new Text(cnt,SWT.LEFT);
Upvotes: 0
Views: 2537
Reputation: 36904
Group
extends Composite
. That means that both of them can have child elements. Both can be placed inside the other. Your problem seems to be caused by the fact that your Group
doesn't have a Layout
. It's not enough to set a Layout
to the Composite
.
Here is a minimal example:
public static void main(String[] args)
{
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("StackOverflow");
shell.setLayout(new GridLayout(1, false));
Group group = new Group(shell, SWT.NONE);
group.setText("Group");
group.setLayout(new GridLayout(1, false));
Composite composite = new Composite(group, SWT.NONE);
composite.setLayout(new GridLayout(2, true));
new Label(composite, SWT.NONE).setText("left");
new Label(composite, SWT.NONE).setText("right");
shell.pack();
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
{
display.sleep();
}
}
display.dispose();
}
Upvotes: 4