RFR: 8325154: resizeColumnToFitContent is slower than it needs to be

Robert Lichtenberger rlichten at openjdk.org
Wed Feb 7 10:02:02 UTC 2024


On Wed, 7 Feb 2024 08:52:32 GMT, Marius Hanl <mhanl at openjdk.org> wrote:

>> The PR simply moves column and view-updates outside the loop. Since the column or view never changes within the for-loop it is not necessary to call these again and again.
>
> modules/javafx.controls/src/main/java/javafx/scene/control/skin/TableColumnHeader.java line 670:
> 
>> 668:             cell.updateTableRow(tableRow);
>> 669:             cell.updateIndex(row);
>> 670: 
> 
> we could also check if we need/can call `tableRow.applyCss();` just only one time (below) (e.g. at first?),
> May works and improve performance, or may not work

That doesn't work unfortunately. I tried this:

        boolean tableRowHasCss = false;
        for (int row = 0; row < rows; row++) {
            tableRow.updateIndex(row);
            cell.updateIndex(row);

            if ((cell.getText() != null && !cell.getText().isEmpty()) || cell.getGraphic() != null) {
                if (!tableRowHasCss) {
                    tableRow.applyCss();
                    tableRowHasCss = true;
                }
                maxWidth = Math.max(maxWidth, cell.prefWidth(-1));
            }
        }

but if you have a table with this css:

.oddbig .table-row-cell:odd{
    -fx-font-size: 36;
}


Then only the css of the first row will be taken into account, i.e. the column wont size correctly.
I've recorded a little video of the effect at https://youtu.be/-p0pv-i4K2s

-------------

PR Review Comment: https://git.openjdk.org/jfx/pull/1358#discussion_r1481219613


More information about the openjfx-dev mailing list