Wrapping broken in ScrolledForm with GridLayout? [message #334471] |
Wed, 11 February 2009 12:18 ![Go to next message Go to next message](theme/Solstice/images/down.png) |
No real name![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=fonolit%40web.de) Messages: 3 Registered: July 2009 |
Junior Member |
|
|
Maybe it's just my fault but I can't make labels in a SrolledForm get
wrapped correctly when I use GridLayout. With TableWrapLayout everything
works fine - but I can't use it, because I need vertical space grabbing...
The attached running code demonstrates the problem (Eclipse 3.3 or 3.4).
As I said replacing GridLayout with TableWrapLayout and GridData with
corresponding TableWrapData makes wrapping work.
Interestingly wrapping works until the first reflow() happens on the
ScrolledForm. Also wrapping of the section's description works fine.
A workaround I found is to set the label's GridData.widthHint to say 200.
Then label wrapping will work until the actual width is less than 200. But
the workaround has a bad side effect. It makes the height reserved for the
label be calculated based on the widthHint instead of it's actual width.
This makes setting the widthHint to small values a bad idea. :-(
Have I done something wrong or should I report a bug on this?
Thanks for your help :-)
By the way the code demonstrates another problem: a section with vertical
space grabbing consumes space even if it is collapsed. As a workaround I
change the GridData in an ExpansionListener (not shown here). Another bug?
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.forms.ManagedForm;
import org.eclipse.ui.forms.SectionPart;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.Section;
public class GridLayoutFormTest {
private static final String LABEL_TEXT = "Wrapping of this text label "
+ "stops working after the form's first reflow.";
private static final String SECTION_DESCRIPTION = "A long section
description "
+ "that requires wrapping. This works just as expected. "
+ "Watch all this text being wrapped correctly: "
+ "bla bla bla bla bla bla bla bla...";
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText(GridLayoutFormTest.class.getName());
shell.setLayout(new FillLayout());
FormToolkit toolkit = new FormToolkit(display);
ScrolledForm form = toolkit.createScrolledForm(shell);
form.setText("Form");
form.getBody().setLayout(new GridLayout());
ManagedForm mform = new ManagedForm(toolkit, form);
Composite parent = mform.getForm().getBody();
createSection(mform, parent);
createSection(mform, parent);
shell.setSize(500, 500);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
private static Control createSection(final ManagedForm mform,
Composite parent) {
FormToolkit toolkit = mform.getToolkit();
SectionPart sectionPart = new SectionPart(parent, toolkit,
Section.TITLE_BAR | Section.DESCRIPTION | Section.TWISTIE
| Section.EXPANDED);
sectionPart.initialize(mform);
Section section = sectionPart.getSection();
section.setText("Section");
section.setDescription(SECTION_DESCRIPTION);
GridData labelLayoutData = new GridData(SWT.FILL, SWT.FILL, true,
true);
labelLayoutData.widthHint = SWT.DEFAULT;
section.setLayoutData(labelLayoutData);
Composite client = toolkit.createComposite(section, SWT.WRAP);
section.setClient(client);
client.setLayout(new GridLayout());
Label label = toolkit.createLabel(client, LABEL_TEXT, SWT.WRAP);
label.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
Button button = new Button(client, SWT.PUSH);
button.setText("Reflow Form");
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
mform.reflow(true);
}
});
button.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
return section;
}
}
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03815 seconds