Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to exclude widget from parent's size calculation
How to exclude widget from parent's size calculation [message #637867] Tue, 09 November 2010 08:35 Go to next message
Graeme  is currently offline Graeme Friend
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 #637870 is a reply to message #637867] Tue, 09 November 2010 08:54 Go to previous messageGo to next message
Devi Vara Prasad Bandaru is currently offline Devi Vara Prasad BandaruFriend
Messages: 100
Registered: March 2010
Location: Hyderabad
Senior Member

Did you set the width hint for label's grid data?

Re: How to exclude widget from parent's size calculation [message #637955 is a reply to message #637867] Tue, 09 November 2010 13:10 Go to previous messageGo to next message
Lakshmi ShanmugamFriend
Messages: 276
Registered: July 2009
Location: India
Senior Member
Also useful --> Understanding Layouts in SWT

Lakshmi P Shanmugam
Re: How to exclude widget from parent's size calculation [message #638134 is a reply to message #637870] Wed, 10 November 2010 06:16 Go to previous messageGo to next message
Graeme  is currently offline Graeme Friend
Messages: 3
Registered: November 2010
Junior Member
Prasad wrote on Tue, 09 November 2010 03:54
Did you set the width hint for label's grid data?

Yes, but that caused the width to be limited to that width hint (if I expanded the panel, the label stayed the same size). I'd like to keep the dynamic wrapping (go to the end of the screen), simply not have the parent panel's original size based on the label's size.
Re: How to exclude widget from parent's size calculation [message #638147 is a reply to message #638134] Wed, 10 November 2010 08:17 Go to previous messageGo to next message
Devi Vara Prasad Bandaru is currently offline Devi Vara Prasad BandaruFriend
Messages: 100
Registered: March 2010
Location: Hyderabad
Senior Member

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);
	}
	



Re: How to exclude widget from parent's size calculation [message #638380 is a reply to message #638147] Thu, 11 November 2010 06:00 Go to previous message
Graeme  is currently offline Graeme Friend
Messages: 3
Registered: November 2010
Junior Member
Prasad wrote on Wed, 10 November 2010 03: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.


Ah it was SWT.FILL I was missing. Thanks a lot!
Previous Topic:enabling mouse wheel scroll in .Xdefaults
Next Topic:Extend Popup menu of Text
Goto Forum:
  


Current Time: Fri Aug 23 21:53:02 GMT 2019

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

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

Back to the top