How to Write a Mouse-Wheel Listener
by, 04-26-2012 at 08:39 PM (554 Views)
When mouse’s wheel get rotated, it is been notified by the mouse wheel events. All mice don’t have wheels and in those cases generation of mouse wheel events is never done. No other way is present to detect programmatically that whether mouse wheel is present in a mouse or not.
MouseAdapter AWT class shall be used alternatively that would be implementing the interface MouseWheelListener, for creation of the MouseWheelEvent and overriding the specific event methods.
It is not important usually to make the implementation of the mouse wheel listener as scrolling is the basic job of the mouse wheel. Automatically, scroll panes register the listeners which appropriately react with the mouse wheel.
However, custom component creation so that it could be used in scroll pane, scrolling behavior shall be customized. You may need to set the block increments and unit.
For generation of the mouse wheel events, it is must that cursor is present at the component which is registered for listening the mouse wheel events. Scrolling which is done, either WHEEL_BLOCK_SCROLL or WHEEL_UNIT_SCROLL, is dependent upon the platform. Scrolling of the mouse wheel is also dependent upon platform. Both amount and type of scrolling might be set through control panel of the mouse.