mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-13 07:17:13 -06:00
Smooth Scrolling: fixed jittery scrolling with trackpad or Magic Mouse (if smooth scrolling is enabled)
This commit is contained in:
@@ -144,8 +144,7 @@ public class FlatScrollPaneUI
|
|||||||
scrollpane.isWheelScrollingEnabled() )
|
scrollpane.isWheelScrollingEnabled() )
|
||||||
{
|
{
|
||||||
if( e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL &&
|
if( e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL &&
|
||||||
e.getPreciseWheelRotation() != 0 &&
|
isPreciseWheelEvent( e ) )
|
||||||
e.getPreciseWheelRotation() != e.getWheelRotation() )
|
|
||||||
{
|
{
|
||||||
// precise scrolling
|
// precise scrolling
|
||||||
mouseWheelMovedPrecise( e );
|
mouseWheelMovedPrecise( e );
|
||||||
@@ -179,6 +178,30 @@ public class FlatScrollPaneUI
|
|||||||
return UIManager.getBoolean( "ScrollPane.smoothScrolling" );
|
return UIManager.getBoolean( "ScrollPane.smoothScrolling" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private long lastPreciseWheelWhen;
|
||||||
|
|
||||||
|
private boolean isPreciseWheelEvent( MouseWheelEvent e ) {
|
||||||
|
double preciseWheelRotation = e.getPreciseWheelRotation();
|
||||||
|
if( preciseWheelRotation != 0 && preciseWheelRotation != e.getWheelRotation() ) {
|
||||||
|
// precise wheel event
|
||||||
|
lastPreciseWheelWhen = e.getWhen();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If a non-precise wheel event occurs shortly after a precise wheel event,
|
||||||
|
// then it is probably still a precise wheel but the precise value
|
||||||
|
// is by chance an integer value (e.g. 1.0 or 2.0).
|
||||||
|
// Not handling this special case, would start an animation for smooth scrolling,
|
||||||
|
// which would be interrupted soon when the next precise wheel event occurs.
|
||||||
|
// This would result in jittery scrolling. E.g. on a MacBook using Trackpad or Magic Mouse.
|
||||||
|
if( e.getWhen() - lastPreciseWheelWhen < 1000 )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// non-precise wheel event
|
||||||
|
lastPreciseWheelWhen = 0;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private void mouseWheelMovedPrecise( MouseWheelEvent e ) {
|
private void mouseWheelMovedPrecise( MouseWheelEvent e ) {
|
||||||
// return if there is no viewport
|
// return if there is no viewport
|
||||||
JViewport viewport = scrollpane.getViewport();
|
JViewport viewport = scrollpane.getViewport();
|
||||||
|
|||||||
Reference in New Issue
Block a user