mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-13 07:17:13 -06:00
ScrollBar: fixed issue with updating thumb location (regressing since commit 2c3ef226692fa39b7e6eca3192d197c0b0753aa1)
This commit is contained in:
@@ -474,7 +474,8 @@ public class FlatScrollBarUI
|
|||||||
if( animator != null )
|
if( animator != null )
|
||||||
animator.cancel();
|
animator.cancel();
|
||||||
|
|
||||||
scrollbar.setValueIsAdjusting( true );
|
if( useValueIsAdjusting )
|
||||||
|
scrollbar.setValueIsAdjusting( true );
|
||||||
|
|
||||||
// if invoked while animation is running, calculation of new value
|
// if invoked while animation is running, calculation of new value
|
||||||
// should start at the previous target value
|
// should start at the previous target value
|
||||||
@@ -485,12 +486,18 @@ public class FlatScrollBarUI
|
|||||||
|
|
||||||
r.run();
|
r.run();
|
||||||
|
|
||||||
|
// do not use animation if started dragging thumb
|
||||||
|
if( isDragging ) {
|
||||||
|
inRunAndSetValueAnimated = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int newValue = scrollbar.getValue();
|
int newValue = scrollbar.getValue();
|
||||||
if( newValue != oldValue ) {
|
if( newValue != oldValue ) {
|
||||||
scrollbar.setValue( oldValue );
|
scrollbar.setValue( oldValue );
|
||||||
|
|
||||||
setValueAnimated( newValue );
|
setValueAnimated( newValue );
|
||||||
} else
|
} else if( useValueIsAdjusting )
|
||||||
scrollbar.setValueIsAdjusting( false );
|
scrollbar.setValueIsAdjusting( false );
|
||||||
|
|
||||||
inRunAndSetValueAnimated = false;
|
inRunAndSetValueAnimated = false;
|
||||||
@@ -500,9 +507,11 @@ public class FlatScrollBarUI
|
|||||||
private Animator animator;
|
private Animator animator;
|
||||||
private int targetValue = Integer.MIN_VALUE;
|
private int targetValue = Integer.MIN_VALUE;
|
||||||
private int delta;
|
private int delta;
|
||||||
|
private boolean useValueIsAdjusting = true;
|
||||||
|
|
||||||
public void setValueAnimated( int value ) {
|
public void setValueAnimated( int value ) {
|
||||||
scrollbar.setValueIsAdjusting( true );
|
if( useValueIsAdjusting )
|
||||||
|
scrollbar.setValueIsAdjusting( true );
|
||||||
|
|
||||||
// create animator
|
// create animator
|
||||||
if( animator == null ) {
|
if( animator == null ) {
|
||||||
@@ -518,13 +527,14 @@ public class FlatScrollBarUI
|
|||||||
|
|
||||||
// re-enable valueIsAdjusting if disabled while animation is running
|
// re-enable valueIsAdjusting if disabled while animation is running
|
||||||
// (e.g. in mouse released listener)
|
// (e.g. in mouse released listener)
|
||||||
if( !scrollbar.getValueIsAdjusting() )
|
if( useValueIsAdjusting && !scrollbar.getValueIsAdjusting() )
|
||||||
scrollbar.setValueIsAdjusting( true );
|
scrollbar.setValueIsAdjusting( true );
|
||||||
|
|
||||||
scrollbar.setValue( targetValue - delta + Math.round( delta * fraction ) );
|
scrollbar.setValue( targetValue - delta + Math.round( delta * fraction ) );
|
||||||
}, () -> {
|
}, () -> {
|
||||||
targetValue = Integer.MIN_VALUE;
|
targetValue = Integer.MIN_VALUE;
|
||||||
scrollbar.setValueIsAdjusting( false );
|
if( useValueIsAdjusting )
|
||||||
|
scrollbar.setValueIsAdjusting( false );
|
||||||
});
|
});
|
||||||
|
|
||||||
animator.setResolution( resolution );
|
animator.setResolution( resolution );
|
||||||
@@ -564,10 +574,24 @@ public class FlatScrollBarUI
|
|||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void mousePressed( MouseEvent e ) {
|
public void mousePressed( MouseEvent e ) {
|
||||||
|
// Do not use valueIsAdjusting here (in runAndSetValueAnimated())
|
||||||
|
// for smooth scrolling because super.mousePressed() enables this itself
|
||||||
|
// and super.mouseRelease() disables it later.
|
||||||
|
// If we would disable valueIsAdjusting here (in runAndSetValueAnimated())
|
||||||
|
// and move the thumb with the mouse, then the thumb location is not updated
|
||||||
|
// if later scrolled with a key (e.g. HOME key).
|
||||||
|
useValueIsAdjusting = false;
|
||||||
|
|
||||||
runAndSetValueAnimated( () -> {
|
runAndSetValueAnimated( () -> {
|
||||||
super.mousePressed( e );
|
super.mousePressed( e );
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseReleased( MouseEvent e ) {
|
||||||
|
super.mouseReleased( e );
|
||||||
|
useValueIsAdjusting = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---- class FlatScrollListener -------------------------------------------
|
//---- class FlatScrollListener -------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user