From 3de489f693d51eb4f5ee4f20e5c2573ac6c89169 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Fri, 9 Oct 2020 16:27:52 +0200 Subject: [PATCH] TabbedPane: - fixed jittery animated scrolling tabs - support disabling animated scrolling with "ScrollPane.smoothScrolling=false" --- .../com/formdev/flatlaf/ui/FlatTabbedPaneUI.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTabbedPaneUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTabbedPaneUI.java index 2911f304..5f408f53 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTabbedPaneUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTabbedPaneUI.java @@ -100,6 +100,7 @@ import com.formdev.flatlaf.util.UIScale; * @uiDefault TabbedPane.showTabSeparators boolean * @uiDefault TabbedPane.tabSeparatorsFullHeight boolean * @uiDefault TabbedPane.hasFullBorder boolean + * @uiDefault ScrollPane.smoothScrolling boolean * * @author Karl Tauber */ @@ -577,6 +578,16 @@ public class FlatTabbedPaneUI return tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT; } + protected boolean isSmoothScrollingEnabled() { + if( !Animator.useAnimation() ) + return false; + + // Note: Getting UI value "ScrollPane.smoothScrolling" here to allow + // applications to turn smooth scrolling on or off at any time + // (e.g. in application options dialog). + return UIManager.getBoolean( "ScrollPane.smoothScrolling" ); + } + //---- class FlatScrollableTabButton -------------------------------------- protected class FlatScrollableTabButton @@ -705,15 +716,14 @@ public class FlatTabbedPaneUI return; // do not use animation if disabled - if( !Animator.useAnimation() ) { + if( !isSmoothScrollingEnabled() ) { tabViewport.setViewPosition( viewPosition ); setRolloverTab( lastMouseX, lastMouseY ); return; } // remember start and target view positions - if( startViewPosition == null ) - startViewPosition = tabViewport.getViewPosition(); + startViewPosition = tabViewport.getViewPosition(); targetViewPosition = viewPosition; // create animator