I need my JTable to automatically re-size its column widths to fit the content. I found the TableColumnAdjuster
class very useful. But there's a small problem. Say i have 5 columns, and their content is very short. In that case, if i use the auto adjuster, it sets the first four columns widths according to their content and gives all the rest of space to the last column. Please see the example.
Here the last column, Balance
is given all the excess space. But what if i need to give that space to one of the middle columns. In the above case, i need to assign that space to the third column, name
. I tried modifying the TableColumnAdjuster
class's adjustColumns()
method. But I couldn't get it working.
I tried both column.setPreferredWidth()
and column.setWidth()
for changing column sizes. But seems it doesn't change anything. How can I effectively change the column sizes of a JTable
. If there's some other alternative or a direct answer to my main problem, that's better. Thanks!