Reputation: 425
I created JPanel with implemented Scrollable
interface and overrided method getScrollableBlockIncrement
.
I placed JPanel into JScrollPane.
And JPanel contains several components with same height. This height is the unitIncrement.
Now, when I click on arrow on the vertical scrollbar, viewport moves by unitIncrement.
But, when I move knob with mouse, viewport moves by pixels.
How to make viewport to move only by unitIncrement?
Update:
Knob is the middle button on scrollbar, on track, to drag it. As shown there How a Scroll Pane Works
I want viewport moves only by unitIncrement in any way. Also when I press left mouse button on knob and drag it. The example behaviour: intellisense in Eclipse.
Update 2:
I tried
myJScrollPane.getVerticalScrollBar().setUnitIncrement(16);
And didn't get desired behaviour.
When I debugged code, I found that parameter unitIncrement is discarded when I drag the knob.
Update 3:
Couldn't find suitable solution with JScrollPane and wrote custom scroll pane.
Upvotes: 0
Views: 723
Reputation: 6475
The answer to your question could be found with a little search effort: How do I speed up the scroll speed in a JScrollPane when using the mouse wheel?
To reiterate, you basically want to modify the JScrollBar
on your JScollPane
.
myJScrollPane.getVerticalScrollBar().setUnitIncrement(16);
Otherwise, you're left with overriding the Scolling event on the JScrollPane to pass in the amount you want to scroll based on the pane that's being scrolled - that's a little messy... so if the first way works for you, that's what I'd go with.
Bottom line: the problem's with JScollPane
- not your Scrollable
class.
Upvotes: 0