Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsSetting the size of an empty Text widget
https://www.eclipse.org/forums/index.php/mv/msg/171493/545466/#msg_545466
If I put text into it first, it gets drawn at the size required to hold the text; so I know the layout can handle the size I'm looking for. I also tried calling setSize() on the Text, before or after I apply the layout data. Nothing seems to work.
]]>Mark Leone2010-07-07T21:22:05-00:00Re: Setting the size of an empty Text widget
https://www.eclipse.org/forums/index.php/mv/msg/171493/545601/#msg_545601
try setting the layout data like this:
Text text = new Text(shell, SWT.BORDER);
GridData textGD = new GridData(GridData.FILL_HORIZONTAL);
text.setLayoutData(textGD);
Works for me. Maybe you have to set textGD.horizontalSpan as well. I
don't know how your layout is set up.
cheers
Peter
On 07.07.10 23:22, Mark Leone wrote:
> Is there some special incantation required to set the size of an empty
> Text widget? I'm using a GridLayout, and I tried setting all the obvious
> parameters on the GridData object: hint = desired size, grab (horiz) =
> true, align (horiz) = SWT.FILL. No matter what I do, the widget is drawn
> at a fixed size, about 5 or 6 characters wide.
>
> If I put text into it first, it gets drawn at the size required to hold
> the text; so I know the layout can handle the size I'm looking for. I
> also tried calling setSize() on the Text, before or after I apply the
> layout data. Nothing seems to work.
>]]>Peter Kanzler2010-07-08T11:40:22-00:00Re: Setting the size of an empty Text widget
https://www.eclipse.org/forums/index.php/mv/msg/171493/545774/#msg_545774
I discovered that the problem was caused by the fact that the Text object in question was being placed in a PageBook. The PageBook API shows that it has its own layout manager implementation, and it doesn't say anything about how to specify layout data for it.
I didn't get a run-time error when I applied the GridData to the Text, which usually happens when I use it with an incompatible layout manager. But I also had tried not applying any layout data to the Text, relying on Text.setSize() to specify the width; and the size setting was ignored in that case as well.
I finally got it to work by creating a Composite to hold the Text. I created the Composite as a child of the PageBook, with no layout data set on it. Then I created and applied a GridLayout to the Composite, added the Text as a child of the Composite, and applied the GridData to the Text as described above. By adding
grab(true, false)
to the method chain on GridDataFactory, and not doing so on any other objects in the row, the Text control now expands to fill all available horizontal space (and contracts accordingly when its parent is made smaller), which is the effect I was aiming for.]]>Mark Leone2010-07-09T04:43:45-00:00