3

Using a JScrollPane's scrollbar arrows to scroll (or by setting up key bindings for the arrow keys) moves the viewport one increment, pauses, then scrolls smoothly. Most scrollbars I've encountered behave the same; there's a slight movement, a pause, and then faster continuous scrolling. Is there any way to avoid the pause, so that scrolling is smooth from start to finish?

mKorbel
  • 108,320
  • 17
  • 126
  • 296
bendicott
  • 370
  • 2
  • 17

2 Answers2

6

The initial delay and repeat rate for key events is specified by the host operating system. Users often adjust the default values in the host's (platform dependent) preference control panel. Similarly, a platform's subclass of BasicScrollBarUI may further condition the throttling, e.g. com.apple.laf.AquaScrollBarUI v. javax.swing.plaf.metal.MetalScrollBarUI.

As these settings may be deeply ingrained or highly personalized, arbitrary changes may be poorly received.

trashgod
  • 196,350
  • 25
  • 213
  • 918
  • I'm working on a JScrollPane to use for a 2D game, so the pause would make player movement awkward. I can see why you would usually not want to change default settings though. – bendicott Aug 24 '11 at 15:29
4

The BasicScrollBarUI is responsible for setting up the timer that does the scrolling.

private final static int scrollSpeedThrottle = 60; // delay in milli seconds
...
scrollListener = createScrollListener();
scrollTimer = new Timer(scrollSpeedThrottle, scrollListener);
scrollTimer.setInitialDelay(300);  // default InitialDelay?

You can see that the repeat rate is faster than the initial delay.

So I would guess you need to create a custom scrollbar UI and override that code.

camickr
  • 308,339
  • 18
  • 152
  • 272