Hi all
It looks like there are two bugs in the existing code which result in incorrect behavior of TableHeaderComponent. It’s about the following piece of code from setColumnWidth function:
const int index = getIndexOfColumnId (columnId, true) + 1;
if (index < getNumColumns (true))
{
const int x = getColumnPosition (index).getX();
resizeColumnsToFit (index, getWidth() - x);
}
When you try to resize the last column to get it smaller, there is no visible column next to the column being resized. So, getIndexOfColumnId() will return -1 and passing -1 to resizeColumnsToFit will result in not resizing of the current column to fit the total width. I think the existing code:
const int index = getIndexOfColumnId (columnId, true) + 1;
should be
// Resize the current column too
const int index = getIndexOfColumnId (columnId, true);
Further, resizeColumnsToFit function operates on absolute indexes of columns and you have to pass an absolute index to the function instead of visible-indexes of visible columns. So changing the call of resizeColumnsToFit to something like
int id = getColumnIdOfIndex(index, true);
resizeColumnsToFit (getIndexOfColumnId(id, false), getWidth() - x);
should fix this problem.