Java trackpad 2-way scroll listener

how can I detect two-finger scrolling on a laptop joystick in java? I searched Google here, but I can’t find anything when scrolling using the trackpad, not to mention how to listen to it. Any help would be greatly appreciated. thanks.

+6
source share
3 answers

When it comes to listening to custom scrolls, you can do this by adding MouseWheelListener to your control. For more information, see How to Write a Mouse Listener.

If it comes to detecting certain events from the trackpad, not the mouse, I don’t know any Java function to implement it.

+4
source

I made this sample program

import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelListener; import javax.swing.JFrame; public class ScrollTest { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(200,200); frame.addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent event) { if (event.isShiftDown()) { System.err.println("Horizontal " + event.getWheelRotation()); } else { System.err.println("Vertical " + event.getWheelRotation()); } } }); frame.setVisible(true); } } 

It will print if the scroll is horizontal or vertical, and how much scroll was there when you scroll in the window that opens on the Mac using the touch panel.

+8
source

Finally, the answer will listen to the scroll. Take a look at my question and answer here: fooobar.com/questions/547872 / ...

The project also detects scroll gestures and communicates them well. Scrolling is as smooth as the cocoa native program.

0
source

Source: https://habr.com/ru/post/902303/


All Articles