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.
Asked
Active
Viewed 1,173 times
12

RoiEX
- 1,186
- 1
- 10
- 37
-
1What about '' node.setOnScroll(new EventHandler()...''? It gives Y and X coordinates. – Felipe Sulser Apr 27 '16 at 20:02
-
It does not trigger on sideway scrolling... – RoiEX Apr 27 '16 at 20:04
-
Had a similar problem once. This was the solution http://stackoverflow.com/questions/12911506/why-jscrollpane-does-not-react-to-mouse-wheel-events JScrollPane did not react to mouse wheel scrolls. – Felipe Sulser Apr 27 '16 at 20:11
-
My problem is, that the event is triggering on normal scroll events, but is not recognizing sideway scrolling as well sideway scrolling... – RoiEX Apr 27 '16 at 20:29
1 Answers
2
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.

RoiEX
- 1,186
- 1
- 10
- 37