|Re: Setting the size of an empty Text widget [message #545601 is a reply to message #545466]
||Thu, 08 July 2010 11:40
| Peter Kanzler
Registered: July 2009
try setting the layout data like this:
Text text = new Text(shell, SWT.BORDER);
GridData textGD = new GridData(GridData.FILL_HORIZONTAL);
Works for me. Maybe you have to set textGD.horizontalSpan as well. I
don't know how your layout is set up.
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.
|Re: Setting the size of an empty Text widget [message #545774 is a reply to message #545601]
||Fri, 09 July 2010 04:43
| Mark Leone
Registered: July 2009
Thanks for the reply, Peter. I usually use the grid data factory class, in which the following code is equivalent to what you posted.|
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 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.
Powered by FUDForum
. Page generated in 0.03883 seconds