RoiEX RoiEX - 5 months ago 53x
Java Question

Horizontal Scrolling Listener

I feel like I have searched half the Web and found no solution...

I have a java application displaying a Map(different countries etc.).

currently you are able to scroll down and up using your mouse wheel...

I want it so, that you are able to scroll sideways (horizontally).

All I need is a Listener (in Swing or Javafx does not matter) triggering whenever the mousewheel gets tilted, without the need for a focus of the map (hovering with your mouse should be enough the windows should still be focused) and without any visible scrollbars.


Using the following code every time you scroll sideways a message gets printed out...

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 {
    public void start(Stage primaryStage) {
        try {
            BorderPane root = new BorderPane();
            Scene scene = new Scene(root,400,400);
            scene.addEventHandler(new EventType<Event>("HSEvent"), new EventHandler<Event>(){

                public void handle(Event event) {
                    System.out.println("event:" + event.getEventType().getName());
            scene.setOnScroll(new EventHandler<ScrollEvent>(){

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

    public static void main(String[] args) {