Note: Advice in this article will only work for JxBrowser 6. See the corresponding article for JxBrowser 7 here.(注意:本文中的建议仅适用于JxBrowser6,JxBrowser7相应文章请点击这里。)


Using the BrowserView.setMouseEventsHandler(InputEventsHandler<MouseEvent> handler) method you can decide what mouse events should be suppressed before they will be sent to Chromium engine. The following example demonstrates how to suppress mouse wheel events:(使用BrowserView.setMouseEventsHandler(InputEventsHandler 处理程序)方法,您可以决定在将哪些鼠标事件发送到Chromium引擎之前,应先对其进行抑制。下面的示例演示如何抑制鼠标滚轮事件:)

import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.InputEventsHandler;
import com.teamdev.jxbrowser.chromium.swing.BrowserView;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;

/**
 * This sample demonstrates how to register mouse events handler
 * to handle/suppress mouse wheel events.
 */
public class MouseEventsHandlerSample {
    public static void main(String[] args) {
        Browser browser = new Browser();
        BrowserView view = new BrowserView(browser);

        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(700, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);

        view.setMouseEventsHandler(new InputEventsHandler<MouseEvent>() {
            @Override
            public boolean handle(MouseEvent event) {
                return event.getID() == MouseEvent.MOUSE_WHEEL;
            }
        });

        browser.loadURL("http://www.google.com");
    }
}