【问题标题】:Horizontal Scrolling Listener水平滚动监听器
【发布时间】:2016-08-18 03:16:52
【问题描述】:

我觉得我已经搜索了一半的网络并没有找到解决方案......
我有一个显示地图(不同国家等)的 java 应用程序。
目前您可以使用鼠标滚轮向下和向上滚动...
我想要它,以便您能够横向滚动(水平)。
我所需要的只是一个监听器(在 Swing 或 Javafx 中无关紧要)在鼠标滚轮倾斜时触发,不需要地图的焦点(用鼠标悬停应该足够了,窗口仍然应该被聚焦)并且没有任何可见的滚动条。

【问题讨论】:

  • '' node.setOnScroll(new EventHandler()...'' 怎么样?它给出了 Y 和 X 坐标。
  • 横向滚动不会触发...
  • 曾经遇到过类似的问题。这是stackoverflow.com/questions/12911506/…JScrollPane 对鼠标滚轮滚动没有反应的解决方案。
  • 我的问题是,该事件在正常滚动事件上触发,但无法识别横向滚动以及横向滚动...

标签: java horizontal-scrolling


【解决方案1】:

每次横向滚动时使用以下代码打印出一条消息...

import javafx.application.Application;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.event.EventType;
import javafx.scene.Scene;
import javafx.scene.input.ScrollEvent;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;


public class Main extends Application {
    @Override
    public void start(Stage primaryStage) {
        try {
            BorderPane root = new BorderPane();
            Scene scene = new Scene(root,400,400);
            scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
            primaryStage.setScene(scene);
            scene.setOnScroll(new EventHandler<ScrollEvent>(){

                @Override
                public void handle(ScrollEvent event) {
                    System.out.println("Scroll:" + event.getDeltaX());
                }
            });
            primaryStage.show();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        launch(args);
    }
}

需要考虑的一点: 显然,当将 JFXPanel 嵌入到 JFrame 中时,横向滚动事件没有通过。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-08
    • 1970-01-01
    • 2012-09-13
    • 2014-11-15
    • 2020-05-23
    • 2015-09-20
    • 2021-08-13
    • 1970-01-01
    相关资源
    最近更新 更多