List of usage examples for javafx.scene Node setOnMouseMoved
public final void setOnMouseMoved(EventHandler<? super MouseEvent> value)
From source file:Main.java
public static void addMarker(final XYChart<?, ?> chart, final StackPane chartWrap) { final Line valueMarker = new Line(); final Node chartArea = chart.lookup(".chart-plot-background"); chartArea.setOnMouseMoved(new EventHandler<MouseEvent>() { @Override/* w w w. j av a 2s .c om*/ public void handle(MouseEvent event) { Point2D scenePoint = chart.localToScene(event.getSceneX(), event.getSceneY()); Point2D position = chartWrap.sceneToLocal(scenePoint.getX(), scenePoint.getY()); Bounds chartAreaBounds = chartArea.localToScene(chartArea.getBoundsInLocal()); valueMarker.setStartY(0); valueMarker.setEndY(chartWrap.sceneToLocal(chartAreaBounds).getMaxY() - chartWrap.sceneToLocal(chartAreaBounds).getMinY()); valueMarker.setStartX(0); valueMarker.setEndX(0); valueMarker.setTranslateX(position.getX() - chartWrap.getWidth() / 2); double ydelta = chartArea.localToScene(0, 0).getY() - chartWrap.localToScene(0, 0).getY(); valueMarker.setTranslateY(-ydelta * 2); } }); chartWrap.getChildren().add(valueMarker); }