0

Is it possible to specify the step size of a JScrollPane when dragging it?

I'm aware of setUnitIncrement and setBlockIncrement, but these do not work when dragging the scrollbar.

Edit: AdjustmentListener

final AdjustmentListener myAdjustmentListener = new AdjustmentListener() {
   @Override
   public void adjustmentValueChanged(AdjustmentEvent e) {
       if (e.getAdjustmentType() == AdjustmentEvent.TRACK){
           e.getAdjustable().setUnitIncrement(500);
           e.getAdjustable().setBlockIncrement(500);
       }
   }
};
Stefan Surkamp
  • 972
  • 1
  • 16
  • 31

2 Answers2

1

Setting setUnitIncrement and setBlockIncrement values only changes the scroll speed when scrolling with a mouse wheel, the arrow keys, and the scroll bar arrows. These values do not change the scroll speed when the scroll bars are dragged.

However the AdjustmentListener can be added to a scrollbar to listen to the scrollbar movements.

4J41
  • 5,005
  • 1
  • 29
  • 41
  • yes this is controled by proportional value Rectangle from JViewport v.s. JComponent in JScrollPane – mKorbel Dec 12 '13 at 20:12
  • I edited my answer and added the AdjustmentListener I'm currently using. Which event should I use to listen for scrollbar movements? – Stefan Surkamp Dec 12 '13 at 23:13
0

An AdjustmentListener should do the magic for you. Did you look at this: How to make JScrollPane scroll 1 line per mouse wheel step?

Community
  • 1
  • 1
Ashish
  • 1,121
  • 2
  • 15
  • 25
  • Yes, my running ``AdjustmentListener`` is derived from that. I've edited my original post and added the current version of the listener. But it only covers mouse-wheel scrolling and scroll bar arrows, not dragging of the bar itself. – Stefan Surkamp Dec 12 '13 at 23:15