[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: Auto-sizing table columns

Veronika Irvine wrote:

Also compare isVisible and getVisible.

"Veronika Irvine" <veronika_irvine@xxxxxxx> wrote in message news:csk3vm$7u5$1@xxxxxxxxxxxxxxxxxx
See:


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

"Bill Ewing" <ewing@xxxxxxxxx> wrote in message news:csk2qj$1nm$1@xxxxxxxxxxxxxxxxxx
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.