The question:
In Swing, when my MouseWheelListener receives a MouseWheelEvent, how can I combine the multitude of parameters contained within that event to obtain a single signed integer representing the number of units to scroll by, taking into account the fact that the "event type" may be either MouseWheelEvent.WHEEL_UNIT_SCROLL or MouseWheelEvent.WHEEL_BLOCK_SCROLL ?
Background:
Anyone who has ever had to deal with Swing's MouseWheelEvent must have noticed that it is preposterously complicated: instead of a single parameter containing the amount by which to scroll, it offers 5 parameters: getScrollType(), getScrollAmount(), getWheelRotation(), getPreciseWheelRotation(), and getUnitsToScroll().
The "scroll type" appears to be crucial for this, however the documentation (Which nowadays can be found at Oracle - Class MouseWheelEvent) mentions but does not explain the value of WHEEL_BLOCK_SCROLL.
Adding insult to injury, Oracle's own "tutorial" on the mouse wheel listener Oracle: How to Write a Mouse-Wheel Listener completely fails to show what to do when WHEEL_BLOCK_SCROLL is received, and instead shows how to display "WHEEL_BLOCK_SCROLL" when that happens.
It appears that WHEEL_BLOCK_SCROLL is very seldom implemented, so it is quite unclear how to handle it, and how to even observe it happening. One of the very rare pieces
of code that you can find out there which attempts to do something meaningful with WHEEL_BLOCK_SCROLL is at Github / iconfinder / batik / sources / org / apache / batik / swing / JSVGScrollPane.java but the code is commented-out, so I cannot trust that it ever worked.
Perhaps events of type WHEEL_BLOCK_SCROLL can be triggered if you go to "Mouse" settings in Windows, and in the "Roll the mouse wheel to scroll" box select "One screen at a time" instead of "Multiple lines at a time", but I have not tried this yet. Here is an unanswered question about this on stackoverflow: How do I generate a java swing WHEEL_BLOCK_SCROLL event?