Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Wrapping broken in ScrolledForm with GridLayout?
Wrapping broken in ScrolledForm with GridLayout? [message #334471] Wed, 11 February 2009 12:18 Go to next message
No real name is currently offline No real nameFriend
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;
}
}
Re: Wrapping broken in ScrolledForm with GridLayout? [message #334537 is a reply to message #334471] Mon, 16 February 2009 18:24 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 3
Registered: July 2009
Junior Member
Since nobody seems to have an answer I would like to file a bug. OK?
Re: Wrapping broken in ScrolledForm with GridLayout? [message #334595 is a reply to message #334537] Thu, 19 February 2009 15:38 Go to previous message
No real name is currently offline No real nameFriend
Messages: 3
Registered: July 2009
Junior Member
I reported this problem as a bug here:

http://bugs.eclipse.org/265389

So please add your comments there if you have any.
Thank you.
Previous Topic:Load my plugin at startup in particular order
Next Topic:TreeViewerFocusCellManager support for SWT.MULTI
Goto Forum:
  


Current Time: Fri Dec 27 03:02:30 GMT 2024

Powered by FUDForum. Page generated in 0.03158 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top