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 ));

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s