mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 06:27:13 -06:00
Smooth Scrolling:
- fixed jittery repeating-scrolling with PageUp/Down keys when reaching the top/bottom/left/right of the viewport (see FlatScrollBarUI.setValueAnimated()) - temporary change viewport scroll mode only if it is JViewport.BLIT_SCROLL_MODE - use JViewport.SIMPLE_SCROLL_MODE when temporary disabling blitting
This commit is contained in:
@@ -521,23 +521,25 @@ public class FlatScrollBarUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setValueAnimated( int initialValue, int value ) {
|
public void setValueAnimated( int initialValue, int value ) {
|
||||||
|
if( useValueIsAdjusting )
|
||||||
|
scrollbar.setValueIsAdjusting( true );
|
||||||
|
|
||||||
|
// (always) set scrollbar value to initial value
|
||||||
|
scrollbar.setValue( initialValue );
|
||||||
|
|
||||||
// do some check if animation already running
|
// do some check if animation already running
|
||||||
if( animator != null && animator.isRunning() && targetValue != Integer.MIN_VALUE ) {
|
if( animator != null && animator.isRunning() && targetValue != Integer.MIN_VALUE ) {
|
||||||
// ignore requests if animation still running and scroll direction is the same
|
// Ignore requests if animation still running and scroll direction is the same
|
||||||
// and new value is within currently running animation
|
// and new value is within currently running animation.
|
||||||
// (this may occur when repeat-scrolling via keyboard)
|
// Without this check, repeating-scrolling via keyboard would become
|
||||||
|
// very slow when reaching the top/bottom/left/right of the viewport,
|
||||||
|
// because it would start a new 200ms animation to scroll a few pixels.
|
||||||
if( value == targetValue ||
|
if( value == targetValue ||
|
||||||
(value > startValue && value < targetValue) || // scroll down/right
|
(value > startValue && value < targetValue) || // scroll down/right
|
||||||
(value < startValue && value > targetValue) ) // scroll up/left
|
(value < startValue && value > targetValue) ) // scroll up/left
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( useValueIsAdjusting )
|
|
||||||
scrollbar.setValueIsAdjusting( true );
|
|
||||||
|
|
||||||
// set scrollbar value to initial value
|
|
||||||
scrollbar.setValue( initialValue );
|
|
||||||
|
|
||||||
startValue = initialValue;
|
startValue = initialValue;
|
||||||
targetValue = value;
|
targetValue = value;
|
||||||
|
|
||||||
|
|||||||
@@ -561,21 +561,16 @@ public class FlatScrollPaneUI
|
|||||||
*/
|
*/
|
||||||
static void runWithoutBlitting( Container scrollPane, Runnable r ) {
|
static void runWithoutBlitting( Container scrollPane, Runnable r ) {
|
||||||
// prevent the viewport to immediately repaint using blitting
|
// prevent the viewport to immediately repaint using blitting
|
||||||
JViewport viewport = null;
|
JViewport viewport = (scrollPane instanceof JScrollPane) ? ((JScrollPane)scrollPane).getViewport() : null;
|
||||||
int oldScrollMode = 0;
|
boolean isBlitScrollMode = (viewport != null) ? viewport.getScrollMode() == JViewport.BLIT_SCROLL_MODE : false;
|
||||||
if( scrollPane instanceof JScrollPane ) {
|
if( isBlitScrollMode )
|
||||||
viewport = ((JScrollPane) scrollPane).getViewport();
|
viewport.setScrollMode( JViewport.SIMPLE_SCROLL_MODE );
|
||||||
if( viewport != null ) {
|
|
||||||
oldScrollMode = viewport.getScrollMode();
|
|
||||||
viewport.setScrollMode( JViewport.BACKINGSTORE_SCROLL_MODE );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
r.run();
|
r.run();
|
||||||
} finally {
|
} finally {
|
||||||
if( viewport != null )
|
if( isBlitScrollMode )
|
||||||
viewport.setScrollMode( oldScrollMode );
|
viewport.setScrollMode( JViewport.BLIT_SCROLL_MODE );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user