Java 触控板 2 指滚动侦听器

发布于 2024-12-17 19:49:40 字数 88 浏览 0 评论 0 原文

我如何在java中检测笔记本电脑触控板上的两指滚动?我一直在谷歌和这里搜索,但找不到任何关于使用触控板滚动的内容,更不用说如何监听它了。任何帮助将不胜感激。谢谢。

how can i detect a 2-finger scroll on a laptop trackpad in java? I've been searching google and here but can't find anything on scrolling using a trackpad let alone how to listen for it. any help would be greatly appreciated. thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

空宴 2024-12-24 19:49:40

我制作了这个示例程序,

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);
    }
}

它将打印滚动是水平还是垂直的,以及当您在带有触摸板的 Mac 上打开的窗口中滚动时滚动的程度。

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 the scroll was when you scroll within the opened window on a mac with a touchpad.

情徒 2024-12-24 19:49:40

如果这是关于监听用户滚动,您可以通过添加 MouseWheelListener 到您的控件。有关详细信息,请参阅如何编写鼠标轮侦听器

如果这是关于检测来自触控板而不是鼠标的特定事件,我不知道有任何 Java 功能可以实现这一点。

If this is about listening for user scrolls, you can do it by adding a MouseWheelListener to your control. See How to Write a Mouse-Wheel Listener for more information.

If this is about detecting specific events from the trackpad and not the mouse, I don't known of any Java feature to implement this.

嘦怹 2024-12-24 19:49:40

最后一个答案将聆听本机滚动。在这里看看我的问题和答案: https://stackoverflow.com/a/31190973/155137

该项目还检测滚动手势并很好地报告它们。滚动就像原生可可应用程序一样流畅。

Finally an answer that will listen to native scrolling. Take a look at my question and answer here: https://stackoverflow.com/a/31190973/155137

The project also detects scroll gestures and reports them nicely. The scrolling is as smooth as a native cocoa application.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文