After a couple of days spent to understand why/how ListCellSkin listening to the listView's fixedCellSize is misbehaving (there are multiple stumbling stones in its listener registration, details in the bug report https://bugs.openjdk.java.net/browse/JDK-8246745) - I'm about to remove that listener completely.

All it does is to copy the value of the listView's fixedCellSize to the skin, without any action triggered. Later on, that copied value is used in the computeXXHeight methods.

Code snippets:

    // fields
    private double fixedCellSize;
    private boolean fixedCellSizeEnabled;

    // listener:
    registerChangeListener(listView.fixedCellSizeProperty(), e -> {
        this.fixedCellSize = getSkinnable().getListView().getFixedCellSize();
        this.fixedCellSizeEnabled = fixedCellSize > 0;
    });

    // usage
    @Override
    protected double computePrefHeight(...) {
        if (fixedCellSizeEnabled) {
            return fixedCellSize;
        }
        // do the per-row calc ...
    }

Instead of keeping the fields in-sync with those of the listView, we could just query the current state:

    @Override
    protected double computePrefHeight(...) {
        double fixedCellSize = getFixedCellSize();
        if (fixedCellSize > 0) {
            return fixedCellSize;
        }
        // do the per-row calc ...
    }

    double getFixedCellSize() {
        ListView<?> listView = getSkinnable().getListView();
return listView != null ? listView.getFixedCellSize() : Region.USE_COMPUTED_SIZE;
    }

Doing so would by-pass the pitfalls of corrently re-wiring the listener to the path property (it's added complexity without benefit). Plus cleanup unneeded aliasing (which I think is a code smell anyway)

Opinions, please

-- Jeanette


Reply via email to