javaswingevent-dispatch-threadswingxjxtable

Is there a way to call JXTable.packAll() in a way that does not lock up the swing thread?


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.


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.