How to smoothly scroll through lists in Swing

On scrolling lists, the iPhone animates seamlessly. Ignoring the effect of inertia (although it would be great) - how can I make the swing scroll scroll so smoothly?

There are other examples, such as browsers, but they use their own controls that I cannot use with Swing.

+4
source share
2 answers

If you are using a JList , try overwriting getScrollableUnitIncrement(Rectangle, int, int) and getScrollableBlockIncrement(Rectangle, int, int) to return the user increment. 2 pixels instead of the default values โ€‹โ€‹calculated from the list entry height.

+4
source

I'm not sure if this answers your question, but I had a similar problem. My problem was that dragging the vertical JScrollPane handle caused the JList to scroll in blocks rather than units, that is, the top cell was always displayed in its entirety, except when the list was scrolling from the bottom.

Curiously, this only happened when using the look of Windows. Using L & F by default, I got the behavior that I wanted. And after many digging, I found this post , which showed that there is a L & F property for this. By default, this is true for Windows L & F, but you can set it to false:

 UIManager.put("List.lockToPositionOnScroll", Boolean.FALSE); 
+3
source

Source: https://habr.com/ru/post/1286271/


All Articles