I want to add a Composite to Eclipse that appears when a certain checkbox is checked. The composite will be comprised of 2 parts: a WARNING_ICON and a label with some text.
I can't seem to get the layout quite right - I want to display the image and label side by side. Here's my section of the code:
final Composite warningComposite = new Composite(parent, SWT.NONE);
warningComposite.setLayout(new GridLayout(2, false));
warningComposite.setLayoutData(new GridData(0, 0, true, false));
Label l = SWTUtilities.createLabel(composite, "", -1, -1, 1, GridData.BEGINNING);
final Image img = PlatformUI.getWorkbench().getDisplay().getSystemImage(SWT.ICON_WARNING);
l.setImage(img);
l.setLayoutData(new GridData());
l = SWTUtilities.createLabel(composite, "Wizards Gone Wild", -1, -1, 1, GridData.END);
And the SWTUtilities.createLabel method:
public static Label createLabel(final Composite parent, final String label, final int width, final int indent, final int span, final int style) {
Assert.isNotNull(parent);
Assert.isNotNull(label);
final Label control = new Label(parent, SWT.WRAP);
control.setText(label);
if (width > 0 || indent > 0 || span > 0) {
final GridData data = new GridData(style);
if (width > 0)
data.widthHint = width;
if (indent > 0)
data.verticalIndent = indent;
if (span > 1)
data.horizontalSpan = span;
control.setLayoutData(data);
}
return control;
}