From 305e9e602e82c8eae98237e702b463a6c666f024 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Tue, 11 Aug 2020 10:13:55 +0200 Subject: [PATCH] ScrollBar: fixed jittery scrolling when in repeating mode (hold down mouse button) and smooth scrolling enabled --- .../java/com/formdev/flatlaf/ui/FlatScrollBarUI.java | 4 ++-- .../flatlaf/testing/FlatSmoothScrollingTest.java | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) 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() {