Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Auto-sizing table columns
Auto-sizing table columns [message #449159] Tue, 18 January 2005 22:32 Go to next message
Bill Ewing is currently offline Bill EwingFriend
Messages: 49
Registered: July 2009
Member
Often, we want to automatically widen a column in a table to make if fill
out any extra space when the table control is resized.

This should be pretty easy to do, right? We can just take the available
space, subtract the other column widths, see what's left over and then
decide whether we should plump up a certain column.

But, what about the vertical scroll bar? It takes width too. So, we have
to see if it exists and if it is visible, and then account for its width
too.

The right API's would seem to be:
ScrollBar sb = table.getVerticalBar();
and
sb.getVisible();

The code sample below illustrates this but it doesn't work because
getVisible always returns true, NO MATTER WHAT.

Anyone know a solution to this problem? Our next attempt would be to do
something really hideous like trying to use one of the API's to tell us
what column a certain point is in to indirectly determine whether the
scrollbar is there (yeccchh).

TIA, Bill.

=====================================

private void maximizeTableColWidth(Table t, int column, int minWidth) {

// Determine overall width available for use by the table
int availableWidth = t.getSize().x - t.getBorderWidth() * 2;

// Subtract the widths of all columns except the one to be maximized
for (int i = 0; i < t.getColumns().length; i++) {
if (i != column ) {
availableWidth -= t.getColumn(i).getWidth();
}
}

// If vertical scrollbar is present, subtract its width too
if (t.getVerticalBar() != null) {
if (t.getVerticalBar().getVisible()) {
availableWidth -= t.getVerticalBar().getSize().x;
}
}

// Set the column to avail width or its minimum - whichever is larger
t.getColumn(column).setWidth( availableWidth > minWidth ?
availableWidth : minWidth);
}
Re: Auto-sizing table columns [message #449161 is a reply to message #449159] Tue, 18 January 2005 22:52 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
See:

http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet77.java?rev=HEAD&a mp;content-type=text/vnd.viewcvs-markup

"Bill Ewing" <ewing@irori.com> wrote in message
news:csk2qj$1nm$1@www.eclipse.org...
> Often, we want to automatically widen a column in a table to make if fill
> out any extra space when the table control is resized.
>
> This should be pretty easy to do, right? We can just take the available
> space, subtract the other column widths, see what's left over and then
> decide whether we should plump up a certain column.
> But, what about the vertical scroll bar? It takes width too. So, we have
> to see if it exists and if it is visible, and then account for its width
> too.
>
> The right API's would seem to be:
> ScrollBar sb = table.getVerticalBar();
> and
> sb.getVisible();
>
> The code sample below illustrates this but it doesn't work because
> getVisible always returns true, NO MATTER WHAT.
>
> Anyone know a solution to this problem? Our next attempt would be to do
> something really hideous like trying to use one of the API's to tell us
> what column a certain point is in to indirectly determine whether the
> scrollbar is there (yeccchh).
>
> TIA, Bill.
>
> =====================================
>
> private void maximizeTableColWidth(Table t, int column, int minWidth) {
>
> // Determine overall width available for use by the table
> int availableWidth = t.getSize().x - t.getBorderWidth() * 2;
>
> // Subtract the widths of all columns except the one to be maximized
> for (int i = 0; i < t.getColumns().length; i++) {
> if (i != column ) {
> availableWidth -= t.getColumn(i).getWidth();
> }
> }
>
> // If vertical scrollbar is present, subtract its width too
> if (t.getVerticalBar() != null) {
> if (t.getVerticalBar().getVisible()) {
> availableWidth -= t.getVerticalBar().getSize().x;
> }
> }
>
> // Set the column to avail width or its minimum - whichever is larger
> t.getColumn(column).setWidth( availableWidth > minWidth ?
> availableWidth : minWidth);
> }
>
>
>
Re: Auto-sizing table columns [message #449162 is a reply to message #449161] Tue, 18 January 2005 22:54 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
Also compare isVisible and getVisible.

"Veronika Irvine" <veronika_irvine@oti.com> wrote in message
news:csk3vm$7u5$1@www.eclipse.org...
> See:
>
> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet77.java?rev=HEAD&a mp;content-type=text/vnd.viewcvs-markup
>
> "Bill Ewing" <ewing@irori.com> wrote in message
> news:csk2qj$1nm$1@www.eclipse.org...
>> Often, we want to automatically widen a column in a table to make if fill
>> out any extra space when the table control is resized.
>>
>> This should be pretty easy to do, right? We can just take the available
>> space, subtract the other column widths, see what's left over and then
>> decide whether we should plump up a certain column.
>> But, what about the vertical scroll bar? It takes width too. So, we
>> have to see if it exists and if it is visible, and then account for its
>> width too.
>>
>> The right API's would seem to be:
>> ScrollBar sb = table.getVerticalBar();
>> and
>> sb.getVisible();
>>
>> The code sample below illustrates this but it doesn't work because
>> getVisible always returns true, NO MATTER WHAT.
>>
>> Anyone know a solution to this problem? Our next attempt would be to do
>> something really hideous like trying to use one of the API's to tell us
>> what column a certain point is in to indirectly determine whether the
>> scrollbar is there (yeccchh).
>>
>> TIA, Bill.
>>
>> =====================================
>>
>> private void maximizeTableColWidth(Table t, int column, int minWidth) {
>>
>> // Determine overall width available for use by the table
>> int availableWidth = t.getSize().x - t.getBorderWidth() * 2;
>>
>> // Subtract the widths of all columns except the one to be maximized
>> for (int i = 0; i < t.getColumns().length; i++) {
>> if (i != column ) {
>> availableWidth -= t.getColumn(i).getWidth();
>> }
>> }
>>
>> // If vertical scrollbar is present, subtract its width too
>> if (t.getVerticalBar() != null) {
>> if (t.getVerticalBar().getVisible()) {
>> availableWidth -= t.getVerticalBar().getSize().x;
>> }
>> }
>>
>> // Set the column to avail width or its minimum - whichever is larger
>> t.getColumn(column).setWidth( availableWidth > minWidth ?
>> availableWidth : minWidth);
>> }
>>
>>
>>
>
>
Re: Auto-sizing table columns [message #449181 is a reply to message #449161] Wed, 19 January 2005 00:23 Go to previous messageGo to next message
Bill Ewing is currently offline Bill EwingFriend
Messages: 49
Registered: July 2009
Member
Veronika Irvine wrote:

> See:

>
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet77.java?rev=HEAD&a mp;content-type=text/vnd.viewcvs-markup

> "Bill Ewing" <ewing@irori.com> wrote in message
> news:csk2qj$1nm$1@www.eclipse.org...
>> Often, we want to automatically widen a column in a table to make if fill
>> out any extra space when the table control is resized.
>>
>> This should be pretty easy to do, right? We can just take the available
>> space, subtract the other column widths, see what's left over and then
>> decide whether we should plump up a certain column.
>> But, what about the vertical scroll bar? It takes width too. So, we have
>> to see if it exists and if it is visible, and then account for its width
>> too.
>>

Nope. The sample you pointed me at merely did what I was already doing.
>> The right API's would seem to be:
>> ScrollBar sb = table.getVerticalBar();
>> and
>> sb.getVisible();
>>
>> The code sample below illustrates this but it doesn't work because
>> getVisible always returns true, NO MATTER WHAT.
>>
>> Anyone know a solution to this problem? Our next attempt would be to do
>> something really hideous like trying to use one of the API's to tell us
>> what column a certain point is in to indirectly determine whether the
>> scrollbar is there (yeccchh).
>>
>> TIA, Bill.
>>
>> =====================================
>>
>> private void maximizeTableColWidth(Table t, int column, int minWidth) {
>>
>> // Determine overall width available for use by the table
>> int availableWidth = t.getSize().x - t.getBorderWidth() * 2;
>>
>> // Subtract the widths of all columns except the one to be maximized
>> for (int i = 0; i < t.getColumns().length; i++) {
>> if (i != column ) {
>> availableWidth -= t.getColumn(i).getWidth();
>> }
>> }
>>
>> // If vertical scrollbar is present, subtract its width too
>> if (t.getVerticalBar() != null) {
>> if (t.getVerticalBar().getVisible()) {
>> availableWidth -= t.getVerticalBar().getSize().x;
>> }
>> }
>>
>> // Set the column to avail width or its minimum - whichever is larger
>> t.getColumn(column).setWidth( availableWidth > minWidth ?
>> availableWidth : minWidth);
>> }
>>
>>
>>
Re: Auto-sizing table columns [message #449183 is a reply to message #449162] Wed, 19 January 2005 00:28 Go to previous message
Bill Ewing is currently offline Bill EwingFriend
Messages: 49
Registered: July 2009
Member
Veronika Irvine wrote:

> Also compare isVisible and getVisible.

> "Veronika Irvine" <veronika_irvine@oti.com> wrote in message
> news:csk3vm$7u5$1@www.eclipse.org...
>> See:
>>
>>
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet77.java?rev=HEAD&a mp;content-type=text/vnd.viewcvs-markup
>>
>> "Bill Ewing" <ewing@irori.com> wrote in message
>> news:csk2qj$1nm$1@www.eclipse.org...
>>> Often, we want to automatically widen a column in a table to make if fill
>>> out any extra space when the table control is resized.
>>>
>>> This should be pretty easy to do, right? We can just take the available
>>> space, subtract the other column widths, see what's left over and then
>>> decide whether we should plump up a certain column.
>>> But, what about the vertical scroll bar? It takes width too. So, we
>>> have to see if it exists and if it is visible, and then account for its
>>> width too.
>>>
>>> The right API's would seem to be:
>>> ScrollBar sb = table.getVerticalBar();
>>> and
>>> sb.getVisible();
>>>
>>> The code sample below illustrates this but it doesn't work because
>>> getVisible always returns true, NO MATTER WHAT.
>>>
>>> Anyone know a solution to this problem? Our next attempt would be to do
>>> something really hideous like trying to use one of the API's to tell us
>>> what column a certain point is in to indirectly determine whether the
>>> scrollbar is there (yeccchh).
>>>
>>> TIA, Bill.
>>>
>>> =====================================
>>>
>>> private void maximizeTableColWidth(Table t, int column, int minWidth) {
>>>
>>> // Determine overall width available for use by the table
>>> int availableWidth = t.getSize().x - t.getBorderWidth() * 2;
>>>
>>> // Subtract the widths of all columns except the one to be maximized
>>> for (int i = 0; i < t.getColumns().length; i++) {
>>> if (i != column ) {
>>> availableWidth -= t.getColumn(i).getWidth();
>>> }
>>> }
>>>
>>> // If vertical scrollbar is present, subtract its width too
>>> if (t.getVerticalBar() != null) {
>>> if (t.getVerticalBar().getVisible()) {
>>> availableWidth -= t.getVerticalBar().getSize().x;
>>> }
>>> }
>>>
>>> // Set the column to avail width or its minimum - whichever is larger
>>> t.getColumn(column).setWidth( availableWidth > minWidth ?
>>> availableWidth : minWidth);
>>> }


Thank you, Veronika, for trying. isVisible worked the same as getVisible.

If you actually think/know the code you suggested works, could you let me
know? A lot of respondents put up answers that look logical, but cannot
spend the time to test them.

Your response did inspire some thoughts: we are using JFace, and it
creates the table object automatically by itself. The constructor
arguments that allow you to set the style and scroll bars are thus hidden,
and there is no post-constructor setStyle method. Thus, my problem may
lie in the design of JFace. However, I can't believe the JFace guys would
be so stupid as to eliminate an option like that, so it has to be
something we're doing wrong.

Anybody got a clue? TIA for all responses.
Previous Topic:No background on text, label...
Next Topic:JFace Table: getColumnImage always returns all black
Goto Forum:
  


Current Time: Thu Apr 25 03:38:48 GMT 2024

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

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

Back to the top