Different scroll speeds on JComponent using a single JScrollBar

Can I define different scroll speeds on a JScrollBar?

For example, suppose we have an image drawn with a height of 1000 that does not match my frame. Therefore, I created a default JScrollBaracting as expected, assuming viewportheights of 200:

[^]
(*) -> The topmost pixel in the frame has height 0 of the image
 |
 |
 |
 |
[v]

[^]
 |
(*) -> The topmost pixel in the frame has height 200 of the image
 |
 |
 |
[v]

[^]
 |
 |
(*) -> The topmost pixel in the frame has height 400 of the image
 |
 |
[v]

Now my question is: can I change this behavior? For example, I would like it to act as follows:

[^]
(*) -> The topmost pixel in the frame has height 0 of the image!
 |
 |
 |
 |
[v]

[^]
 |
(*) -> The topmost pixel in the frame has height 300 of the image!
 |
 |
 |
[v]

[^]
 |
 |
(*)  -> The topmost pixel in the frame has height 650 of the image!
 |
 |
[v]

, , , . , . , , JScrollBar, . Swing?

+4
1

JScrollBar

 public int getUnitIncrement(int direction) {
     int superValue=super.getUnitIncrement(direction);
//define a speedScaleValue is calculated based on value and maximum
     return superValue*speedScaleValue; 
 }
+3

All Articles