mediocre
mediocre

Reputation: 564

SWT Label/Button not showing up in composite

I'm trying to add a Label or a Button to a child Composite but it's not working as expected.

display = Display.getCurrent();
parentShell = display.getActiveShell();
shell = new Shell(parentShell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
shell.setText(title);

GridLayout layout = new GridLayout(1, false);
shell.setLayout(layout);

// Content composite
contentComposite = new Composite(shell, SWT.BORDER);
GridLayout contentLayout = new GridLayout(2, true);
contentComposite.setLayout(contentLayout);
contentComposite.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));

// Default Version
defaultVersionComposite = new Composite(contentComposite, SWT.BORDER);
defaultVersionComposite.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));

// Versions in Tabs
versionComposite = new Composite(contentComposite, SWT.BORDER);
versionComposite.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
Button button = new Button(versionComposite, SWT.PUSH);
button.setText("Test");

Right now it looks like this.

enter image description here

Any idea what's going on there?

Thanks!

Upvotes: 1

Views: 1108

Answers (1)

Baz
Baz

Reputation: 36884

Your two sub-composites don't have Layouts assigned to them. Just add these two lines:

defaultVersionComposite.setLayout(new GridLayout());
versionComposite.setLayout(new GridLayout());

Upvotes: 3

Related Questions