Force a SWT Text to Wrap

Usually, to force a Text widget to wrap, you are supposed to add the SWT.WRAP style.
But sometimes, it does not work.

This is because its size is not set.
One way to solve this is to make it use the whole horizontal space.

// May not wrap
Text myText = new Text( parent, SWT.MULTI | SWT.READ_ONLY | SWT.WRAP );

// With this in addition, it will wrap
myText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ));

About this entry