0

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.

Stanislav
  • 425
  • 1
  • 5
  • 14
  • 4
    possible duplicate of [How to make JScrollPane scroll 1 line per mouse wheel step?](http://stackoverflow.com/questions/11397581/how-to-make-jscrollpane-scroll-1-line-per-mouse-wheel-step) – Lukas Knuth Aug 05 '12 at 19:30
  • See also [*Implementing a Scrolling-Savvy Client*](http://docs.oracle.com/javase/tutorial/uiswing/components/scrollpane.html#scrollable). – trashgod Aug 05 '12 at 20:28
  • Does _knob with mouse_ mean [scroll wheel](http://en.wikipedia.org/wiki/Scroll_wheel)? – trashgod Aug 05 '12 at 20:31
  • Lukas Knuth, useful link, thanks. But this is not duplicate. – Stanislav Aug 06 '12 at 09:04
  • Trashgod, I read this and didn't find solution there. See update. – Stanislav Aug 06 '12 at 09:14

1 Answers1

0

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.

Community
  • 1
  • 1
Nick Rippe
  • 6,465
  • 14
  • 30