diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatScrollBarUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatScrollBarUI.java index d25103ed..87d43bc2 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatScrollBarUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatScrollBarUI.java @@ -477,13 +477,13 @@ public class FlatScrollBarUI if( useValueIsAdjusting ) scrollbar.setValueIsAdjusting( true ); + int oldValue = scrollbar.getValue(); + // if invoked while animation is running, calculation of new value // should start at the previous target value if( targetValue != Integer.MIN_VALUE ) scrollbar.setValue( targetValue ); - int oldValue = scrollbar.getValue(); - r.run(); // do not use animation if started dragging thumb diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatSmoothScrollingTest.java b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatSmoothScrollingTest.java index 6967b338..7080d86e 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatSmoothScrollingTest.java +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatSmoothScrollingTest.java @@ -558,11 +558,20 @@ public class FlatSmoothScrollingTest } } + /** + * One or two values between two equal values are considered "temporary", + * which means that they are the target value for the following scroll animation. + */ private boolean isTemporaryValue( List chartData, int i ) { if( i == 0 || i == chartData.size() - 1 ) return false; - return chartData.get( i - 1 ).value == chartData.get( i + 1 ).value; + double valueBefore = chartData.get( i - 1 ).value; + double valueAfter = chartData.get( i + 1 ).value; + + return valueBefore == valueAfter || + (i < chartData.size() - 2 && valueBefore == chartData.get( i + 2 ).value) || + (i > 1 && chartData.get( i - 2 ).value == valueAfter); } private int chartWidth() {