How to exclude widget from parent's size calculation [message #637867] |
Tue, 09 November 2010 08:35 |
Graeme Messages: 3 Registered: November 2010 |
Junior Member |
|
|
Hi, I'm having an issue with SWT that is driving me nuts and I'm hoping someone can help.
What I have is on a properties panel, a bunch of textboxes and some other widgets, and underneath one I have a fairly lengthy message I display with a standard Label. The behaviour I have is text wrapping, which works dynamically (this is done using a GridData object which grabs excess horizontal space, and setting the labels style to SWT.WRAP).
The problem is that when I first load the panel, the long message forces the parent panel to become way wider than is attractive because it tries to fit my message on one line. While this "all-on-one-line" is correct if a user purposely expands the panel to be that wide, I'd like the Properties Panel to layout ignoring this label (just size based on the textboxes and other components on the screen) and have the Label grab whatever space is available after the component has been laid out.
I've tried a bunch of stuff, but I haven't been able to get it to work without setting the width of the label to a static size (which screws up dynamic sizing obviously). Any ideas?
Thanks in advance,
Graeme
|
|
|
|
|
|
Re: How to exclude widget from parent's size calculation [message #638147 is a reply to message #638134] |
Wed, 10 November 2010 08:17 |
|
Setting width hint doesn't prevent the label from expanding when the panel is expanded. Try setting the border for the composite on which the label is added and see if the composite is resizing along with the properties view. Even the style flag set for creating the grid data could also be the problem. Here is a small snippet which i tried.
public void createControls(Composite parent,
TabbedPropertySheetPage aTabbedPropertySheetPage) {
super.createControls(parent, aTabbedPropertySheetPage);
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(2, false));
Label label = getWidgetFactory().createLabel(composite, "Text:");
GridData labelData = new GridData(SWT.LEFT, SWT.CENTER, false, false);
label.setLayoutData(labelData);
Text text = getWidgetFactory().createText(composite, "", SWT.BORDER);
GridData textData = new GridData(SWT.FILL, SWT.FILL, true, true);
text.setLayoutData(textData);
Label lengthyLabel = getWidgetFactory().createLabel(composite, "", SWT.WRAP);
lengthyLabel.setText("This is a very lengthy text.This is a very lengthy text.This is a very lengthy text.This is a very lengthy text.This is a very lengthy text.");
GridData lengthyLabelData = new GridData(SWT.FILL, SWT.CENTER, true, true);
// lengthyLabelData = new GridData(SWT.LEFT, SWT.CENTER, true, true);
lengthyLabelData.widthHint = 150;
lengthyLabelData.horizontalSpan = 2;
lengthyLabel.setLayoutData(lengthyLabelData);
}
Regards,
Prasad
http://marketplace.eclipse.org/user/9964/listings
|
|
|
|
Powered by
FUDForum. Page generated in 0.02712 seconds