3

I'm trying to wrap this text automatically, but it doesn't wrap. I'm trying with the code below, not sure what's wrong with the code. This is

protected Control createContents(Composite parent){
    Composite composite = new Composite(parent, SWT.WRAP);
    composite.setLayout(new GridLayout());
    composite.setLayoutData(new GridData(SWT.HORIZONTAL, SWT.TOP, false, false));

    Group group = new Group(composite, SWT.NONE);
    group.setText("my group");
    group.setLayout(new GridLayout(2, false));
    group.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    Button button = new Button(group2,SWT.CHECK);
    GridData data = new GridData(SWT.HORIZONTAL, SWT.TOP, false, true, 1, 1);
    button.setLayoutData(data);

    Label label= new Label(group, SWT.WRAP);
    data = new GridData(GridData.FILL_HORIZONTAL);
    label.setLayoutData(data);
    label.setText("my long text is very long, I need to wrap this very long text lalalalalalalalalalalalalala");
}
Todd
  • 30,472
  • 11
  • 81
  • 89
Juseeth
  • 467
  • 1
  • 6
  • 18
  • Possible duplicate of http://stackoverflow.com/q/11772305/2670892 – greg-449 Sep 09 '15 at 16:01
  • @greg-449 : It is wrapping when I set the width hint to certain number, but when I maximize the dialog still it is filling the horizontal space, with out SWT.HORIZONTAL it doesn't wrap. – Juseeth Sep 09 '15 at 16:21

1 Answers1

4

The composite's layoutdata also needs to have grabExcessHorizontal space set to true, i.e.:

composite.setLayoutData(new GridData(SWT.NONE, SWT.TOP, true, false));

I think the wrapping label and all of its parent composites need to have that.

By the way, the style-bit SWT.WRAP doesn't make sense for class Composite.

Lii
  • 11,553
  • 8
  • 64
  • 88
Manuel
  • 649
  • 8
  • 13