Example usage for javafx.scene.control ScrollPane addEventFilter

List of usage examples for javafx.scene.control ScrollPane addEventFilter

Introduction

In this page you can find the example usage for javafx.scene.control ScrollPane addEventFilter.

Prototype

public final <T extends Event> void addEventFilter(final EventType<T> eventType,
        final EventHandler<? super T> eventFilter) 

Source Link

Document

Registers an event filter to this node.

Usage

From source file:Main.java

@Override
public void start(Stage stage) throws Exception {
    ImageView imageView = new ImageView();
    ScrollPane scrollPane = new ScrollPane();
    DoubleProperty zoomProperty = new SimpleDoubleProperty(200);

    zoomProperty.addListener(new InvalidationListener() {
        @Override/*from w  w  w . j  ava2  s.com*/
        public void invalidated(Observable arg0) {
            imageView.setFitWidth(zoomProperty.get() * 2);
            imageView.setFitHeight(zoomProperty.get() * 3);
        }
    });
    scrollPane.addEventFilter(ScrollEvent.ANY, new EventHandler<ScrollEvent>() {
        @Override
        public void handle(ScrollEvent event) {
            if (event.getDeltaY() > 0) {
                zoomProperty.set(zoomProperty.get() * 1.2);
            } else if (event.getDeltaY() < 0) {
                zoomProperty.set(zoomProperty.get() / 1.1);
            }
        }
    });
    imageView.setImage(new Image("http://yourImageURL"));
    imageView.preserveRatioProperty().set(true);
    scrollPane.setContent(imageView);
    stage.setScene(new Scene(scrollPane, 400, 300));
    stage.show();
}