Stefan Surkamp
Stefan Surkamp

Reputation: 992

JScrollPane step size when dragging

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);
       }
   }
};

Upvotes: 0

Views: 708

Answers (2)

Ashish
Ashish

Reputation: 1121

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

Upvotes: 0

4J41
4J41

Reputation: 5095

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.

Upvotes: 1

Related Questions