Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 404
RoiEX Avatar asked Apr 24 '16 20:04

RoiEX


1 Answers

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

One thing to consider: Apparently when embedding a JFXPanel into a JFrame the sideway scrolling event is not getting passed.

like image 110
RoiEX Avatar answered Sep 23 '22 06:09

RoiEX