Question

I am displaying lots of data in JXTable from the SwingX project. After loading the data, I call packAll() on the table but with 200 hundred columns and 30,000 records it might take 5 seconds or more. I'm calling this from the swing thread which means the UI is locked up for those 5 seconds. I tried calling packAll on a background thread and as I suspected, doing so has odd side affects. After calling packAll(), when I hover the mouse over the table, all the numbers in the table appear to be constantly updating to different numbers. Is there any way I can get a reasonable user experience with in JXTable when packing the columns of such a large table.

Was it helpful?

Solution

This loop in ColumnFactory is killing you:

for (int r = 0; r < getRowCount(table); r++) {
        Component comp = renderer.getTableCellRendererComponent(table, table
                .getValueAt(r, column), false, false, r, column);
        width = Math.max(width, comp.getPreferredSize().width);
}

You should probably just set the column widths yourself, or perhaps just load one row, pack the table and then load the rest of the data.

OTHER TIPS

Jay, don't know which part of the answer you marked as correct you mean with "excellent idea" - it's at least a bit unclear. The two suggestions were:

a) do it yourself: leaves open the question as to when and where and how exactly b) two-step loading, which ultimately boils down to measuring the first loaded row only. Which is provided for in ColumnFactory already, please read the api doc for getRowCount(JXTable).

Even if your context is not as uniform as to be solved by a simple override of getRowCount(), a custom ColumnFactory is the way to go: you can implement whatever measuring strategy you choose :-)

@z7sg: nothing's "killing" anything - as you might have noticed if you had read the api doc ;-) Cell measuring isn't entirely trivial, a default implementation cannot fit it all, that's why ColumnFactory is designed for extension: subclass and adjust to your needs.

Cheers Jeanette

200 columns and 30,000 rows is going to take a moment to render. I don't think you are going to be able to eliminate the wait time unless you do something drastic. Your best bet might be to not show the table until the data is loaded.

You say you have 200 columns? Well I doubt all 200 are visible at one time. So what if you just pack the first 10-20 column? This should cut down the time delay by 1/10 or 1/20.

If JXTable doesn't allow you to pack individual columns then you can try using the Table Column Adjuster which I think provides the same functionality on a regular JTable. It allows you to pack individual columns.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top