How to make the VirtualizedScrollPane scroll exactly one row per step?
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.
Use flow.scrollYBy( deltaY ), where deltaY is the height of your row (positive value scrolls down, negative value scrolls up).
@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.
@Jugen Any ideas?
[...]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.
Maybe we should add the stepX and stepY properties with default values?
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.