How do you wrap text for an RTC extension UI without excess white space?
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
Try:
GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo(textLine);
Comments
I added this but it resulted in one line that extended off the page with a horizontal scrollbar.
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);
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.