Search code examples
javajavafxslidepane

JavaFX: How to slide image


How to make image to slide on the pane. I am looking at a functionality similar to Google Maps. When the user swipes (or drags or whatever the name of this event is), I need the image to change its position with regard to the pane it is located in.

Can anyone point at the direction where to look at. Is there anything build in in javafx for this.

Thank you


Solution

  • A ScrollPane's scroll position can be adjusted by holding down the mouse button and moving the mouse, if the pannable Property is set to true:

    // Beware 5400x2700 px image 2MB
    Image image = new Image("http://eoimages.gsfc.nasa.gov/images/imagerecords/73000/73751/world.topo.bathy.200407.3x5400x2700.jpg", true);
    ImageView imageView = new ImageView(image);
    ScrollPane root = new ScrollPane(imageView);
    root.setPannable(true);
    
    Scene scene = new Scene(root, 300, 300);