It's all about the answers!

Ask a question

How do you wrap text for an RTC extension UI without excess white space?


Shawn Carroll (2817) | asked Jan 16 '20, 10:39 a.m.

 I've been following Lab 5 in the RTC Extension workshop trying to create an aspect editor for m extension. I've got all the functionality working but when I try to create long text or labels to describe sections of the ui for the user, I've been having trouble with the text wrapping.


Section textSection = toolkit.createSection(parent, ExpandableComposite.TITLE_BAR);
Composite textComp = toolkit.createComposite(textSection);

textSection.setClient(textComp);
textSection.setText("Text Title");

Text textLine = new Text(textComp, SWT.SINGLE);
textLine.setText(Long text entry);

GridLayoutFactory layoutFactory = GridLayoutFactory.fillDefaults().spacing(HORZ_SPAC, VERT_SPAC).numColumns(1);
layoutFactory.generateLayout(textComp);

This previous code got me one line that extended off screen,

Text textLine = new Text(textComp, SWT.WRAP);
textLine.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false));
textLine.setText(Long text entry);

With this, I still got one line, but I could scroll horizontally to see all the text. When I removed the GridData line, the text would wrap normally like I want it to, but it has twice the height as needed with a ton of extra white space between the text and the next UI object. How can I wrap this text without having extra white space between the UI objects?

One answer



permanent link
David Lafreniere (4.8k7) | answered Jan 16 '20, 11:52 a.m.
FORUM MODERATOR / JAZZ DEVELOPER

Try:
GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo(textLine);


Comments
Shawn Carroll commented Jan 16 '20, 12:52 p.m.

 I added this but it resulted in one line that extended off the page with a horizontal scrollbar.


Shawn Carroll commented Jan 16 '20, 12:55 p.m.
Text textLine = new Text(textComp, SWT.WRAP);
textLine.setText(Long text entry);

GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo(textLine);

GridLayoutFactory layoutFactory = GridLayoutFactory.fillDefaults().spacing(HORZ_SPAC, VERT_SPAC).numColumns(1);


David Lafreniere commented Jan 16 '20, 1:47 p.m.
FORUM MODERATOR / JAZZ DEVELOPER
Sounds like the Text is doing what it should per the GridData given to it. It appears the parent is too wide, so either the Composite, the Section, or the secton's parent (but the entire code is not available so it's hard to say.)

You could give the Text a .Hint to limit the width though.

Also, this question really should be in an Eclipse/SWT forum as it has nothing to do with any of the CLM products.

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.