Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set fixed size to SWT label

Tags:

java

swt

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

like image 333
user758795 Avatar asked Feb 18 '23 12:02

user758795


1 Answers

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);
like image 101
BenG Avatar answered Feb 21 '23 02:02

BenG