Flowless icon indicating copy to clipboard operation
Flowless copied to clipboard

How to make the VirtualizedScrollPane scroll exactly one row per step?

Open PavelTurk opened this issue 7 months ago • 6 comments

Let's suppose that we have a virtual flow with N rows and all rows have the same height. Can someone tell me how to make the mouse scroll step always equal to the fixed size (the height of a row), so that the rows' positions remain aligned relative to the screen? For example, when scrolling down, row 4 should take the place of row 3.

PavelTurk avatar Jun 10 '25 12:06 PavelTurk

Use flow.scrollYBy( deltaY ), where deltaY is the height of your row (positive value scrolls down, negative value scrolls up).

Jugen avatar Jun 17 '25 07:06 Jugen

@Jugen Thank you so much for your response and your help. I'm sorry that I have to open so many issues, but so many questions come up while I'm working on my editor.

Yes, I know about flow.scrollYBy(deltaY). But there are two situations where scrolling is already handled by the library: 1. when a user uses the mouse scroll wheel over the cells; 2. when a user scrolls or clicks on the scrollbar.

I think I can handle the events in the first case, but I don’t understand what I should do with the events from the scrollbar, since I don’t have access to it.

PavelTurk avatar Jun 17 '25 10:06 PavelTurk

@Jugen Any ideas?

PavelTurk avatar Nov 10 '25 22:11 PavelTurk

[...]what I should do with the events from the scrollbar, since I don’t have access to it.

Have you tried using virtualizedScrollPane.setOnScroll(event -> { /*... */ }) to handle the scrolling events? I would expect that this method is called in every instance when a scroll occur and you can overwrite the scrolling this way.

Edit: I have tried testing with that method, and it seems that this comes from the Node class and does not do much on scrolling the pane. The only place where I found the scroll change was with:

scrollPane.estimatedScrollYProperty().addListener((_, before, after) -> {
//...
});

But that will not help you catch the scroll event itself.

Symeon94 avatar Nov 11 '25 06:11 Symeon94

Maybe we should add the stepX and stepY properties with default values?

PavelTurk avatar Nov 11 '25 08:11 PavelTurk

I see that the VirtualizedScrollPane uses scroll bar from JavaFX and sets the increment in setupUnitIncrement which is called in the constructor of the class:

    private static void setupUnitIncrement(ScrollBar bar) {
        bar.unitIncrementProperty().bind(new DoubleBinding() {
            { bind(bar.maxProperty(), bar.visibleAmountProperty()); }


            @Override
            protected double computeValue() {
                double max = bar.getMax();
                double visible = bar.getVisibleAmount();
                return max > visible
                        ? 16 / (max - visible) * max
                        : 0;
            }
        });
    }

If that is what sets the scroll, I don't think it would be hard to allow to set it to a constant value.

Symeon94 avatar Nov 11 '25 08:11 Symeon94