From 44752cc9aaf7085f70cdb5ababfea4c3a7073e80 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Tue, 12 Mar 2024 18:41:47 +0100 Subject: [PATCH] TabbedPane: fixed swapped back and forward scroll buttons when using `TabbedPane.scrollButtonsPlacement = trailing` (regression in FlatLaf 3.3 since commit 97495a6093d0094b89115dac4cc2f9ee26fcdc08) --- CHANGELOG.md | 2 + .../formdev/flatlaf/ui/FlatTabbedPaneUI.java | 38 ++++++++++--------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f34f97e..a8488781 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ FlatLaf Change Log #### Fixed bugs +- TabbedPane: Fixed swapped back and forward scroll buttons when using + `TabbedPane.scrollButtonsPlacement = trailing` (regression in FlatLaf 3.3). - Extras: `FlatSVGIcon` color filters now support linear gradients. (PR #817) 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 1411c9e3..1ea57ff9 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 @@ -3851,6 +3851,8 @@ debug*/ w -= buttonWidth; moreTabsButtonVisible = true; } + + // layout scroll buttons if( useScrollButtons ) { // the tabViewport view size is set in // BasicTabbedPaneUI.TabbedPaneScrollLayout.calculateTabRects(), @@ -3858,6 +3860,15 @@ debug*/ Point viewPosition = tabViewport.getViewPosition(); Dimension viewSize = tabViewport.getViewSize(); + // layout forward button on trailing side + if( !hideDisabledScrollButtons || viewSize.width - viewPosition.x > w ) { + int buttonWidth = forwardButton.getPreferredSize().width; + forwardButton.setBounds( leftToRight ? (x + w - buttonWidth) : x, y, buttonWidth, h ); + x += leftToRight ? 0 : buttonWidth; + w -= buttonWidth; + forwardButtonVisible = true; + } + // layout backward button if( !hideDisabledScrollButtons || viewPosition.x > 0 ) { int buttonWidth = backwardButton.getPreferredSize().width; @@ -3873,15 +3884,6 @@ debug*/ w -= buttonWidth; backwardButtonVisible = true; } - - // layout forward button on trailing side - if( !hideDisabledScrollButtons || viewSize.width - viewPosition.x > w ) { - int buttonWidth = forwardButton.getPreferredSize().width; - forwardButton.setBounds( leftToRight ? (x + w - buttonWidth) : x, y, buttonWidth, h ); - x += leftToRight ? 0 : buttonWidth; - w -= buttonWidth; - forwardButtonVisible = true; - } } } @@ -3927,6 +3929,8 @@ debug*/ h -= buttonHeight; moreTabsButtonVisible = true; } + + // layout scroll buttons if( useScrollButtons ) { // the tabViewport view size is set in // BasicTabbedPaneUI.TabbedPaneScrollLayout.calculateTabRects(), @@ -3934,6 +3938,14 @@ debug*/ Point viewPosition = tabViewport.getViewPosition(); Dimension viewSize = tabViewport.getViewSize(); + // layout forward button on bottom side + if( !hideDisabledScrollButtons || viewSize.height - viewPosition.y > h ) { + int buttonHeight = forwardButton.getPreferredSize().height; + forwardButton.setBounds( x, y + h - buttonHeight, w, buttonHeight ); + h -= buttonHeight; + forwardButtonVisible = true; + } + // layout backward button if( !hideDisabledScrollButtons || viewPosition.y > 0 ) { int buttonHeight = backwardButton.getPreferredSize().height; @@ -3948,14 +3960,6 @@ debug*/ h -= buttonHeight; backwardButtonVisible = true; } - - // layout forward button on bottom side - if( !hideDisabledScrollButtons || viewSize.height - viewPosition.y > h ) { - int buttonHeight = forwardButton.getPreferredSize().height; - forwardButton.setBounds( x, y + h - buttonHeight, w, buttonHeight ); - h -= buttonHeight; - forwardButtonVisible = true; - } } }