Home » Eclipse Projects » Eclipse Platform » Question about width of SWT component
Question about width of SWT component [message #323906] |
Fri, 11 January 2008 16:35  |
Eclipse User |
|
|
|
Originally posted by: ku_long.hotmail.com
Hey,
I have a text SWT component on a UI. I want the text
component can fill the horizon of the default parent
composite. Thus, I create a GridData(GridData.FILL_HORIZONTAL)
and set it to the text component. What I want is if
I resize the parent composite, I want the text component
can fill the horizon automatically. But it turned out
that when I call text.SetText(String), the width of the
text component is always automatically changed to
fit the length of the text. So, if the string is very
long, the width of the parent composite is enlarged.
How can I avoid this?
Thanks.
|
|
|
Re: Question about width of SWT component [message #323907 is a reply to message #323906] |
Fri, 11 January 2008 17:32   |
Eclipse User |
|
|
|
Raymond wrote:
> Hey,
>
> I have a text SWT component on a UI. I want the text
> component can fill the horizon of the default parent composite. Thus, I
> create a GridData(GridData.FILL_HORIZONTAL)
> and set it to the text component. What I want is if I resize the parent
> composite, I want the text component
> can fill the horizon automatically. But it turned out that when I call
> text.SetText(String), the width of the text component is always
> automatically changed to fit the length of the text. So, if the string
> is very long, the width of the parent composite is enlarged. How can I
> avoid this?
> Thanks.
>
Grid data has both an alignment property and a "grab" property:
* The alignment fields (left|top, center, right|bottom, fill) specify
where to place the control *within* the cell.
* The "grab" property specifies whether the column/row that the control
is in should grab the excess horizontal/vertical space in the composite.
So you want to use SWT.FILL for horizontal alignment and "true" for
horizontal grab property:
text.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
Hope this helps.
Matthew
|
|
|
Re: Question about width of SWT component [message #323950 is a reply to message #323907] |
Mon, 14 January 2008 11:38   |
Eclipse User |
|
|
|
Originally posted by: eclipse-news.rizzoweb.com
Matthew Hall wrote:
> Raymond wrote:
>> Hey,
>>
>> I have a text SWT component on a UI. I want the text
>> component can fill the horizon of the default parent composite. Thus,
>> I create a GridData(GridData.FILL_HORIZONTAL)
>> and set it to the text component. What I want is if I resize the
>> parent composite, I want the text component
>> can fill the horizon automatically. But it turned out that when I call
>> text.SetText(String), the width of the text component is always
>> automatically changed to fit the length of the text. So, if the string
>> is very long, the width of the parent composite is enlarged. How can I
>> avoid this?
>> Thanks.
>>
>
> Grid data has both an alignment property and a "grab" property:
> * The alignment fields (left|top, center, right|bottom, fill) specify
> where to place the control *within* the cell.
> * The "grab" property specifies whether the column/row that the control
> is in should grab the excess horizontal/vertical space in the composite.
>
> So you want to use SWT.FILL for horizontal alignment and "true" for
> horizontal grab property:
[copying the SWT newsgroup, as that is the more appropriate forum]
GridData.FILL_HORIZONTAL is already doing exactly that.
The reason the parent control is growing is probably because it's own
layout data (and the layout of its parent) are not putting any
limitation on the size of the parent. Without a size limitation, it will
grow to accommodate the preferred size of its children, in your case a
Text widget, whose preferred size is always going to be wide enough to
display the whole text contents. So you need something to bound the size
of the Text's parent (usually by setting the layout of its parent and
its layout data appropriately).
Hope this helps,
Eric
|
|
| | |
Re: Question about width of SWT component [message #323963 is a reply to message #323960] |
Mon, 14 January 2008 14:45   |
Eclipse User |
|
|
|
You have several choices, but I think you probably want to set a widthHint
in your Text's GridData().
You could then just let the scrolling happen and the user needs to drag the
text to see it:
Text text = new Text (shell, SWT.BORDER);
GridData data = new GridData (SWT.FILL, SWT.CENTER, true, false);
data.widthHint = 100;
text.setLayoutData (data);
Or you could create your Text using SWT.WRAP style:
Text text = new Text (shell, SWT.BORDER | SWT.WRAP);
GridData data = new GridData (SWT.FILL, SWT.CENTER, true, false);
data.widthHint = 100;
text.setLayoutData (data);
Or you could give your Text a scroll bar:
Text text = new Text (shell, SWT.BORDER | SWT.H_SCROLL);
GridData data = new GridData (SWT.FILL, SWT.CENTER, true, false);
data.widthHint = 100;
text.setLayoutData (data);
Hope this helps,
Carolyn
"Raymond" <ku_long@hotmail.com> wrote in message
news:f0bf9c0112d4a42ad2dad143c710199b$1@www.eclipse.org...
> Eric, I think you are right. But I don't know how to set the layout of
> the parent (a composite in my case) of the text component to avoid that.
> I tried lots of things but did not find anything worked.
>
|
|
|
Re: Question about width of SWT component [message #323964 is a reply to message #323950] |
Mon, 14 January 2008 14:47   |
Eclipse User |
|
|
|
Just a reminder to try out the LayoutExample. :)
You can then get an idea of the capabilities of GridLayout, etc.
http://www.eclipse.org/swt/examples.php
Carolyn
"Eric Rizzo" <eclipse-news@rizzoweb.com> wrote in message
news:fmg350$r9k$1@build.eclipse.org...
> Matthew Hall wrote:
>> Raymond wrote:
>>> Hey,
>>>
>>> I have a text SWT component on a UI. I want the text
>>> component can fill the horizon of the default parent composite. Thus, I
>>> create a GridData(GridData.FILL_HORIZONTAL)
>>> and set it to the text component. What I want is if I resize the parent
>>> composite, I want the text component
>>> can fill the horizon automatically. But it turned out that when I call
>>> text.SetText(String), the width of the text component is always
>>> automatically changed to fit the length of the text. So, if the string
>>> is very long, the width of the parent composite is enlarged. How can I
>>> avoid this?
>>> Thanks.
>>>
>>
>> Grid data has both an alignment property and a "grab" property:
>> * The alignment fields (left|top, center, right|bottom, fill) specify
>> where to place the control *within* the cell.
>> * The "grab" property specifies whether the column/row that the control
>> is in should grab the excess horizontal/vertical space in the composite.
>>
>> So you want to use SWT.FILL for horizontal alignment and "true" for
>> horizontal grab property:
>
> [copying the SWT newsgroup, as that is the more appropriate forum]
>
> GridData.FILL_HORIZONTAL is already doing exactly that.
>
> The reason the parent control is growing is probably because it's own
> layout data (and the layout of its parent) are not putting any limitation
> on the size of the parent. Without a size limitation, it will grow to
> accommodate the preferred size of its children, in your case a Text
> widget, whose preferred size is always going to be wide enough to display
> the whole text contents. So you need something to bound the size of the
> Text's parent (usually by setting the layout of its parent and its layout
> data appropriately).
>
> Hope this helps,
> Eric
|
|
|
Re: Question about width of SWT component [message #323965 is a reply to message #323964] |
Mon, 14 January 2008 14:49   |
Eclipse User |
|
|
|
Of course, to get the full benefit of the updated LayoutExample, you need to
be running the latest Integration build of Eclipse.
Carolyn
"Carolyn MacLeod" <Carolyn_MacLeod@ca.ibm.com> wrote in message
news:fmge9e$lhs$1@build.eclipse.org...
> Just a reminder to try out the LayoutExample. :)
> You can then get an idea of the capabilities of GridLayout, etc.
> http://www.eclipse.org/swt/examples.php
>
> Carolyn
>
> "Eric Rizzo" <eclipse-news@rizzoweb.com> wrote in message
> news:fmg350$r9k$1@build.eclipse.org...
>> Matthew Hall wrote:
>>> Raymond wrote:
>>>> Hey,
>>>>
>>>> I have a text SWT component on a UI. I want the text
>>>> component can fill the horizon of the default parent composite. Thus, I
>>>> create a GridData(GridData.FILL_HORIZONTAL)
>>>> and set it to the text component. What I want is if I resize the parent
>>>> composite, I want the text component
>>>> can fill the horizon automatically. But it turned out that when I call
>>>> text.SetText(String), the width of the text component is always
>>>> automatically changed to fit the length of the text. So, if the string
>>>> is very long, the width of the parent composite is enlarged. How can I
>>>> avoid this?
>>>> Thanks.
>>>>
>>>
>>> Grid data has both an alignment property and a "grab" property:
>>> * The alignment fields (left|top, center, right|bottom, fill) specify
>>> where to place the control *within* the cell.
>>> * The "grab" property specifies whether the column/row that the control
>>> is in should grab the excess horizontal/vertical space in the composite.
>>>
>>> So you want to use SWT.FILL for horizontal alignment and "true" for
>>> horizontal grab property:
>>
>> [copying the SWT newsgroup, as that is the more appropriate forum]
>>
>> GridData.FILL_HORIZONTAL is already doing exactly that.
>>
>> The reason the parent control is growing is probably because it's own
>> layout data (and the layout of its parent) are not putting any limitation
>> on the size of the parent. Without a size limitation, it will grow to
>> accommodate the preferred size of its children, in your case a Text
>> widget, whose preferred size is always going to be wide enough to display
>> the whole text contents. So you need something to bound the size of the
>> Text's parent (usually by setting the layout of its parent and its layout
>> data appropriately).
>>
>> Hope this helps,
>> Eric
>
>
|
|
| | | |
Re: Question about width of SWT component [message #323979 is a reply to message #323967] |
Tue, 15 January 2008 06:56  |
Eclipse User |
|
|
|
Raymond,
I had the same problem. What Carolyn is suggesting, will fix it. (It's a
widthHint, not a width limit.) You also still need to set fill + grab on
the GridData object for your Text.
Rgds,
Jasper.
Raymond wrote:
> Carolyn, thank you for your answer. I think I don't want to set the
> data.widthHint to limit the width of the text wedget. I want it can fill
> the herizon when its parent's width changed but don't want its width
> changed when its text string is too long.
>
> I will take a look at the SWT samples.
>
> Thanks.
>
|
|
|
Goto Forum:
Current Time: Sat Jul 19 19:48:58 EDT 2025
Powered by FUDForum. Page generated in 0.04440 seconds
|