mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-10 22:17: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 ) {
|
||||
if( useValueIsAdjusting )
|
||||
scrollbar.setValueIsAdjusting( true );
|
||||
|
||||
// (always) set scrollbar value to initial value
|
||||
scrollbar.setValue( initialValue );
|
||||
|
||||
// do some check if animation already running
|
||||
if( animator != null && animator.isRunning() && targetValue != Integer.MIN_VALUE ) {
|
||||
// ignore requests if animation still running and scroll direction is the same
|
||||
// and new value is within currently running animation
|
||||
// (this may occur when repeat-scrolling via keyboard)
|
||||
// Ignore requests if animation still running and scroll direction is the same
|
||||
// and new value is within currently running animation.
|
||||
// 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 ||
|
||||
(value > startValue && value < targetValue) || // scroll down/right
|
||||
(value < startValue && value > targetValue) ) // scroll up/left
|
||||
return;
|
||||
}
|
||||
|
||||
if( useValueIsAdjusting )
|
||||
scrollbar.setValueIsAdjusting( true );
|
||||
|
||||
// set scrollbar value to initial value
|
||||
scrollbar.setValue( initialValue );
|
||||
|
||||
startValue = initialValue;
|
||||
targetValue = value;
|
||||
|
||||
|
||||
@@ -561,21 +561,16 @@ public class FlatScrollPaneUI
|
||||
*/
|
||||
static void runWithoutBlitting( Container scrollPane, Runnable r ) {
|
||||
// prevent the viewport to immediately repaint using blitting
|
||||
JViewport viewport = null;
|
||||
int oldScrollMode = 0;
|
||||
if( scrollPane instanceof JScrollPane ) {
|
||||
viewport = ((JScrollPane) scrollPane).getViewport();
|
||||
if( viewport != null ) {
|
||||
oldScrollMode = viewport.getScrollMode();
|
||||
viewport.setScrollMode( JViewport.BACKINGSTORE_SCROLL_MODE );
|
||||
}
|
||||
}
|
||||
JViewport viewport = (scrollPane instanceof JScrollPane) ? ((JScrollPane)scrollPane).getViewport() : null;
|
||||
boolean isBlitScrollMode = (viewport != null) ? viewport.getScrollMode() == JViewport.BLIT_SCROLL_MODE : false;
|
||||
if( isBlitScrollMode )
|
||||
viewport.setScrollMode( JViewport.SIMPLE_SCROLL_MODE );
|
||||
|
||||
try {
|
||||
r.run();
|
||||
} finally {
|
||||
if( viewport != null )
|
||||
viewport.setScrollMode( oldScrollMode );
|
||||
if( isBlitScrollMode )
|
||||
viewport.setScrollMode( JViewport.BLIT_SCROLL_MODE );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user