user758795
user758795

Reputation: 449

Set fixed size to SWT label

i want to set a label size to fix size. and not change the label size acceding to it's text how can I do it please?

Thanks

Upvotes: 4

Views: 10032

Answers (1)

BenG
BenG

Reputation: 671

Ideally you'd set the width in the layout you are using. Also, when creating the Label you can set whether you want the contents to wrap or not (i.e. expand vertically).

So here's some examples depending on the layout:

FormLayout:

// Add | SWT.WRAP to get label to wrap
Label testLabel = new Label (parent, SWT.LEFT);
FormData fd = new FormData();
fd.width = 50;
testLabel.setLayoutData (fd);

GridLayout:

// Add | SWT.WRAP to get label to wrap
Label testLabel = new Label (parent, SWT.LEFT);
GridData gd = new GridData ();
gd.widthHint = 50;
testLabel.setLayoutData (gd);

Upvotes: 8

Related Questions