Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Tree Widget Size
Tree Widget Size [message #459936] Fri, 19 August 2005 13:38 Go to next message
Eclipse User
Originally posted by: callum.devnet-uk.net

I've got an plug-in that gets its data from a database. The data is
displayed in Text widgets. The user can update the value of the Text
widgets.

If the updated value is a few characters longer than the original, then
the Text widget is not wide enough to display the full value. I can fix
this by calling pack (), but as there are quite a few of these it seems a
bit tacky.

The other approach is to initially set the width of the Text widgets to a
sensible large number so most values will fit, however obviously has UI
implications.

Is there a better work-around for this? Calling pack () on the widgets
won't kill me, but it does seem a bit ... tacky .. it would be good if the
widget would resize itself after being updated, without me having to say
so.



Also, something else that might be useful for some, would be to have a
method that rather than taking the width in pixels, would be something
like:

setSize(FontData fontdata, int len)

where it would garauntee the Text widget is wide (and possibly high)
enough to display the text of Font using fontdata and string length of
len. On the other hand, it might be deemed to be pointless. I suppose it
might be useful for those who put settings in their application, where
users can change fonts and obviously they'd want the Widgets to display
values properly.

If this is somehow already implemented, then please ignore me. :)

Thanks,

Callum Urquhart
Re: Tree Widget Size [message #460171 is a reply to message #459936] Mon, 22 August 2005 14:20 Go to previous message
Grant Gayed is currently offline Grant Gayed
Messages: 2151
Registered: July 2009
Senior Member
Hi Callum,

There isn't a way to make a Text widget auto-grow itself as its content
grows. However from a UI perspective I don't think that this is an ideal
approach anyways. I believe it's more typical to just set the Text's width
to allow for some growth in the length of its value, and if the user enters
a value that extends beyond its end then just let it scroll. This can be
seen in various places through the eclipse preferences.

You can compute an expected good width for a Text field with:

GC gc = new GC(yourTextWidget);
int width = gc.getFontMetrics().getAverageCharWidth() * desiredCharCount; //
<--
gc.dispose();

Of course I say "expected" because for non-monospaced fonts the actual width
will be dependent on the typed text.

Somewhat related: Text.setTextLimit(int) will set a limit on the number of
characters that the Text will take.

Grant


"Callum Urquhart" <callum@devnet-uk.net> wrote in message
news:b32e803bbb9e4f996494ecbaa7e7bb8f$1@www.eclipse.org...
>
> I've got an plug-in that gets its data from a database. The data is
> displayed in Text widgets. The user can update the value of the Text
> widgets.
>
> If the updated value is a few characters longer than the original, then
> the Text widget is not wide enough to display the full value. I can fix
> this by calling pack (), but as there are quite a few of these it seems a
> bit tacky.
>
> The other approach is to initially set the width of the Text widgets to a
> sensible large number so most values will fit, however obviously has UI
> implications.
>
> Is there a better work-around for this? Calling pack () on the widgets
> won't kill me, but it does seem a bit ... tacky .. it would be good if the
> widget would resize itself after being updated, without me having to say
> so.
>
>
>
> Also, something else that might be useful for some, would be to have a
> method that rather than taking the width in pixels, would be something
> like:
>
> setSize(FontData fontdata, int len)
>
> where it would garauntee the Text widget is wide (and possibly high)
> enough to display the text of Font using fontdata and string length of
> len. On the other hand, it might be deemed to be pointless. I suppose it
> might be useful for those who put settings in their application, where
> users can change fonts and obviously they'd want the Widgets to display
> values properly.
>
> If this is somehow already implemented, then please ignore me. :)
>
> Thanks,
>
> Callum Urquhart
>
Previous Topic:Information about the use of Callback, OS.SendMessage and friends?
Next Topic:swtrenderer
Goto Forum:
  


Current Time: Wed Sep 24 00:25:54 GMT 2014

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

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