I have a Pane which listens for the wheel mouse scroll; as well I have a scroll bar which automatically listens for the wheel mouse scroll. I would like to know how to send to scroll event captured by the Pane to the Scrollbar.
I can’t use a scroll pane because I need a custom implementation of the pane, I already tried to use a scroll pane and it did not cover my needs.
I tried to fire the event and other method but I just can get the event to be passed/propagated/sent to the scrollbar.
Thanks in advance
sample application:
package com.test;
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.geometry.Orientation;
import javafx.scene.Scene;
import javafx.scene.control.ScrollBar;
import javafx.scene.input.ScrollEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
public class ScrollTest extends Application{
@Override
public void start(Stage primaryStage) throws Exception {
final BorderPane root = new BorderPane();
final Pane pane = new Pane();
root.setCenter(pane);
final ScrollBar scrollBar = new ScrollBar();
root.setRight(scrollBar);
pane.addEventFilter(ScrollEvent.ANY, new EventHandler<ScrollEvent>(){
@Override
public void handle(ScrollEvent arg0) {
System.out.println("scrolling on the pane");
Event.fireEvent(scrollBar, arg0);
// scrollBar.getEventDispatcher().dispatchEvent(arg0, arg1)
}
});
scrollBar.setOrientation(Orientation.VERTICAL);
scrollBar.valueProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> ov, Number old_val, final Number new_val) {
System.out.println("scrollBar.valueProperty() changed");
}
});
primaryStage.setScene(new Scene(root, 600, 600));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}