diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e5371aa..19facdba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ FlatLaf Change Log - ComboBox and Spinner: Fixed missing arrow buttons if preferred height is zero. Minimum width of arrow buttons is 3/4 of default width. - TabbedPane: Switch and close tabs on left mouse click only. (PR #595) +- ScrollBar: Show "pressed" feedback on track/thumb only for left mouse button. + If absolute positioning is enabled (the default), then also for middle mouse + button. +- Arrow buttons in ComboBox, Spinner, ScrollBar and TabbedPane: Show "pressed" + feedback only for left mouse button. ## 2.5 diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatArrowButton.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatArrowButton.java index df12e0ec..834eb7c6 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatArrowButton.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatArrowButton.java @@ -25,6 +25,7 @@ import java.awt.Graphics2D; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.JComponent; +import javax.swing.SwingUtilities; import javax.swing.plaf.UIResource; import javax.swing.plaf.basic.BasicArrowButton; @@ -82,14 +83,18 @@ public class FlatArrowButton @Override public void mousePressed( MouseEvent e ) { - pressed = true; - repaint(); + if( SwingUtilities.isLeftMouseButton( e ) ) { + pressed = true; + repaint(); + } } @Override public void mouseReleased( MouseEvent e ) { - pressed = false; - repaint(); + if( SwingUtilities.isLeftMouseButton( e ) ) { + pressed = false; + repaint(); + } } } ); } 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 4da580a2..cb1b7c6c 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 @@ -352,6 +352,9 @@ public class FlatScrollBarUI @Override protected void paintTrack( Graphics g, JComponent c, Rectangle trackBounds ) { + if( trackBounds.isEmpty() || !scrollbar.isEnabled() ) + return; + g.setColor( getTrackColor( c, hoverTrack, isPressed && hoverTrack && !hoverThumb ) ); paintTrackOrThumb( g, c, trackBounds, trackInsets, trackArc ); } @@ -452,18 +455,31 @@ public class FlatScrollBarUI @Override public void mousePressed( MouseEvent e ) { - isPressed = true; - repaint(); + if( SwingUtilities.isLeftMouseButton( e ) || isAbsolutePositioning( e ) ) { + isPressed = true; + repaint(); + + // update hover because BasicScrollBarUI.TrackListener.mousePressed() + // moves the track on middle-click (if absolute positioning is enabled) + if( isAbsolutePositioning( e ) ) + update( e.getX(), e.getY() ); + } } @Override public void mouseReleased( MouseEvent e ) { - isPressed = false; - repaint(); + if( SwingUtilities.isLeftMouseButton( e ) || isAbsolutePositioning( e ) ) { + isPressed = false; + repaint(); + } update( e.getX(), e.getY() ); } + private boolean isAbsolutePositioning( MouseEvent e ) { + return getSupportsAbsolutePositioning() && SwingUtilities.isMiddleMouseButton( e ); + } + private void update( int x, int y ) { boolean inTrack = getTrackBounds().contains( x, y ); boolean inThumb = getThumbBounds().contains( x, y );