I don’t like Vista as it is apparently slower than XP. However I discovered something nice about it. Today, I was doing a build on Vista and I double clicked on Explorer table header to auto-fit a column, I noticed it didn’t fully expanded as I knew there is a long file name in this folder. Bug? I soon realized it only auto-fits the cells that are currently visible. I have to say this is a great idea as user only cares about what they can see when they auto-fit. I verified on Windows XP, it doesn’t work like that so it is obviously a new feature Vista introduced.
TableUtils class in JIDE Grids has autoResizeAllColumns and autoResizeColumn method which will auto-fit the columns in a JTable. If JideTable#setColumnAutoResizable(true), user can double click on the table column header between two columns to auto-fit the column, just like what Excel and Explorer (pre-Vista) does. It worked greatly. However when there are a huge number of rows in that table, or the getValueAt method of the table model is very slow, the cell renderer is slow to create, it could take a long time. User reported this issue on PivotTablePane as the autoResizeAllColumns method is slow on huge pivot table. I’ve been spent time to tune it but still not satisfied with it. But this new discovery on Vista gives me the hope. I quickly changed the code and added an extra parameter “visibleRowsOnly” to TableUtils#autoResizeColumn(…). The performance is excellent (of course, as there are only 20 visible rows when I tested on a table with 10000 rows) as it took less than 1 ms comparing to ~200 ms before. So if you are using this feature in JIDE Grids, you can consider using this new feature if it makes more sense to auto-fit the visible rows only in your application.