Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Table Column Width
Table Column Width [message #464580] Fri, 25 November 2005 12:13 Go to next message
Martin is currently offline MartinFriend
Messages: 35
Registered: July 2009
Member
Hi,

is there a way that the columns of a table are automatically resized
depending on the text that is in it's cells.
At the moment i use the work around to determine the average character
width from a GC and multiply it with the maximum number of characters in
this column, which i think is very messy (especially because it's only the
average character width, so i have to add at least 1 or 2 pixels per
character so that the column is really big enough)

Thanks
Martin
Re: Table Column Width [message #464584 is a reply to message #464580] Fri, 25 November 2005 14:24 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
TableColumn.pack() will size the column to be as wide as its widest item.
It is not "automatic" in that you have to call it each time you change the
text or image for a TableItem.

"Martin" <xx@xx.com> wrote in message
news:45ad0f30aa23f90ce161d177632a7834$1@www.eclipse.org...
> Hi,
> is there a way that the columns of a table are automatically resized
> depending on the text that is in it's cells. At the moment i use the work
> around to determine the average character width from a GC and multiply it
> with the maximum number of characters in this column, which i think is
> very messy (especially because it's only the average character width, so i
> have to add at least 1 or 2 pixels per character so that the column is
> really big enough)
>
> Thanks
> Martin
>
Re: Table Column Width [message #464665 is a reply to message #464584] Mon, 28 November 2005 13:40 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: e.s.com

is there some way to "tell" the table to resize itself to fit the text
size or to adjust according to its parent composite?
Re: Table Column Width [message #464670 is a reply to message #464665] Mon, 28 November 2005 15:20 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
Call TableColumn.pack() on each of the columns and then call
table.getShell().layout(new Control[] {table});


"Erel" <e@s.com> wrote in message
news:cb2d03eb4d6fc749f8a20fd9f43b503e$1@www.eclipse.org...
> is there some way to "tell" the table to resize itself to fit the text
> size or to adjust according to its parent composite?
>
Re: Table Column Width [message #464873 is a reply to message #464584] Wed, 30 November 2005 20:27 Go to previous messageGo to next message
Jeremy Dowdall is currently offline Jeremy DowdallFriend
Messages: 48
Registered: July 2009
Member
Veronika,

Is pack() supposed to work like this for tree columns as well?
When I call pack() it only sizes to the top level items, not the
indented / child ones. this is happening for all columns.
I'm on Linux/GTK if that matters.

thanks!



Veronika Irvine wrote:
> TableColumn.pack() will size the column to be as wide as its widest item.
> It is not "automatic" in that you have to call it each time you change the
> text or image for a TableItem.
>
> "Martin" <xx@xx.com> wrote in message
> news:45ad0f30aa23f90ce161d177632a7834$1@www.eclipse.org...
>
>>Hi,
>>is there a way that the columns of a table are automatically resized
>>depending on the text that is in it's cells. At the moment i use the work
>>around to determine the average character width from a GC and multiply it
>>with the maximum number of characters in this column, which i think is
>>very messy (especially because it's only the average character width, so i
>>have to add at least 1 or 2 pixels per character so that the column is
>>really big enough)
>>
>>Thanks
>>Martin
>>
>
>
>
Re: Table Column Width [message #464875 is a reply to message #464584] Wed, 30 November 2005 20:51 Go to previous messageGo to next message
Jeremy Dowdall is currently offline Jeremy DowdallFriend
Messages: 48
Registered: July 2009
Member
I could be way off, but what the heck! :)

in TreeColumn's Pack routine:

int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
if (OS.gtk_tree_model_get_iter_first (parent.modelHandle, iter)) {
do {
width = Math.max (width, parent.calculateWidth (handle, iter));
} while (OS.gtk_tree_model_iter_next(parent.modelHandle, iter));
}
OS.g_free (iter);


seems that it needs to tunnel down through all the children here, as
it's currently just getting the direct children of the parent tree


Veronika Irvine wrote:
> TableColumn.pack() will size the column to be as wide as its widest item.
> It is not "automatic" in that you have to call it each time you change the
> text or image for a TableItem.
>
> "Martin" <xx@xx.com> wrote in message
> news:45ad0f30aa23f90ce161d177632a7834$1@www.eclipse.org...
>
>>Hi,
>>is there a way that the columns of a table are automatically resized
>>depending on the text that is in it's cells. At the moment i use the work
>>around to determine the average character width from a GC and multiply it
>>with the maximum number of characters in this column, which i think is
>>very messy (especially because it's only the average character width, so i
>>have to add at least 1 or 2 pixels per character so that the column is
>>really big enough)
>>
>>Thanks
>>Martin
>>
>
>
>
Re: Table Column Width [message #464945 is a reply to message #464875] Thu, 01 December 2005 16:14 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
We have had some discussion in the past on our team about this.

The problem is that if you have a TreeItem with subitems with subitems with
subitems with subitem with subitems ..

For each subitem there is some indentation. When you pack the column, if
you include all children (expanded or not) the column could become very wide
just to accomodate this indententation for sublevels even though the
unexpanded children are not visible.

Personally I think pack on a TreeColumn should make the column as wide as
the widest expanded child. I have entered the following bug report:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=118844

"Jeremy Dowdall" <dev@myriadfinancial.com> wrote in message
news:dml3bk$qea$1@news.eclipse.org...
>I could be way off, but what the heck! :)
>
> in TreeColumn's Pack routine:
>
> int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
> if (OS.gtk_tree_model_get_iter_first (parent.modelHandle, iter)) {
> do {
> width = Math.max (width, parent.calculateWidth (handle, iter));
> } while (OS.gtk_tree_model_iter_next(parent.modelHandle, iter));
> }
> OS.g_free (iter);
>
>
> seems that it needs to tunnel down through all the children here, as it's
> currently just getting the direct children of the parent tree
>
Re: Table Column Width [message #464951 is a reply to message #464945] Thu, 01 December 2005 17:17 Go to previous message
Jeremy Dowdall is currently offline Jeremy DowdallFriend
Messages: 48
Registered: July 2009
Member
thanks Veronika, I definitely agree that it doesn't make sense to size
the non-expanded (and thus non-visible) items! :)

any suggestions as to a short term work-around? It doesn't seem that I
can access any size info on a per column per item basis...




Veronika Irvine wrote:
> We have had some discussion in the past on our team about this.
>
> The problem is that if you have a TreeItem with subitems with subitems with
> subitems with subitem with subitems ..
>
> For each subitem there is some indentation. When you pack the column, if
> you include all children (expanded or not) the column could become very wide
> just to accomodate this indententation for sublevels even though the
> unexpanded children are not visible.
>
> Personally I think pack on a TreeColumn should make the column as wide as
> the widest expanded child. I have entered the following bug report:
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=118844
>
> "Jeremy Dowdall" <dev@myriadfinancial.com> wrote in message
> news:dml3bk$qea$1@news.eclipse.org...
>
>>I could be way off, but what the heck! :)
>>
>>in TreeColumn's Pack routine:
>>
>>int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ());
>>if (OS.gtk_tree_model_get_iter_first (parent.modelHandle, iter)) {
>> do {
>> width = Math.max (width, parent.calculateWidth (handle, iter));
>> } while (OS.gtk_tree_model_iter_next(parent.modelHandle, iter));
>>}
>>OS.g_free (iter);
>>
>>
>>seems that it needs to tunnel down through all the children here, as it's
>>currently just getting the direct children of the parent tree
>>
>
>
Previous Topic:finding the base directory for RCP app
Next Topic:Non-embedded ActiveX application automation
Goto Forum:
  


Current Time: Thu Dec 26 22:32:19 GMT 2024

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

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

Back to the top