- 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
This commit is contained in:
Karl Tauber
2022-09-30 19:55:42 +02:00
parent 6e7c2a616b
commit e83c26a76a
3 changed files with 34 additions and 8 deletions

View File

@@ -8,6 +8,11 @@ FlatLaf Change Log
- ComboBox and Spinner: Fixed missing arrow buttons if preferred height is zero. - ComboBox and Spinner: Fixed missing arrow buttons if preferred height is zero.
Minimum width of arrow buttons is 3/4 of default width. Minimum width of arrow buttons is 3/4 of default width.
- TabbedPane: Switch and close tabs on left mouse click only. (PR #595) - 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 ## 2.5

View File

@@ -25,6 +25,7 @@ import java.awt.Graphics2D;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.SwingUtilities;
import javax.swing.plaf.UIResource; import javax.swing.plaf.UIResource;
import javax.swing.plaf.basic.BasicArrowButton; import javax.swing.plaf.basic.BasicArrowButton;
@@ -82,14 +83,18 @@ public class FlatArrowButton
@Override @Override
public void mousePressed( MouseEvent e ) { public void mousePressed( MouseEvent e ) {
pressed = true; if( SwingUtilities.isLeftMouseButton( e ) ) {
repaint(); pressed = true;
repaint();
}
} }
@Override @Override
public void mouseReleased( MouseEvent e ) { public void mouseReleased( MouseEvent e ) {
pressed = false; if( SwingUtilities.isLeftMouseButton( e ) ) {
repaint(); pressed = false;
repaint();
}
} }
} ); } );
} }

View File

@@ -352,6 +352,9 @@ public class FlatScrollBarUI
@Override @Override
protected void paintTrack( Graphics g, JComponent c, Rectangle trackBounds ) { protected void paintTrack( Graphics g, JComponent c, Rectangle trackBounds ) {
if( trackBounds.isEmpty() || !scrollbar.isEnabled() )
return;
g.setColor( getTrackColor( c, hoverTrack, isPressed && hoverTrack && !hoverThumb ) ); g.setColor( getTrackColor( c, hoverTrack, isPressed && hoverTrack && !hoverThumb ) );
paintTrackOrThumb( g, c, trackBounds, trackInsets, trackArc ); paintTrackOrThumb( g, c, trackBounds, trackInsets, trackArc );
} }
@@ -452,18 +455,31 @@ public class FlatScrollBarUI
@Override @Override
public void mousePressed( MouseEvent e ) { public void mousePressed( MouseEvent e ) {
isPressed = true; if( SwingUtilities.isLeftMouseButton( e ) || isAbsolutePositioning( e ) ) {
repaint(); 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 @Override
public void mouseReleased( MouseEvent e ) { public void mouseReleased( MouseEvent e ) {
isPressed = false; if( SwingUtilities.isLeftMouseButton( e ) || isAbsolutePositioning( e ) ) {
repaint(); isPressed = false;
repaint();
}
update( e.getX(), e.getY() ); update( e.getX(), e.getY() );
} }
private boolean isAbsolutePositioning( MouseEvent e ) {
return getSupportsAbsolutePositioning() && SwingUtilities.isMiddleMouseButton( e );
}
private void update( int x, int y ) { private void update( int x, int y ) {
boolean inTrack = getTrackBounds().contains( x, y ); boolean inTrack = getTrackBounds().contains( x, y );
boolean inThumb = getThumbBounds().contains( x, y ); boolean inThumb = getThumbBounds().contains( x, y );