I want to detect mouse click event on a QuadCurve but only on the "stroke" part. To be clear only the green part of the image.
Here, i use a red fill value but in my application i use a transparent fill value. So detecting click on the visible part of the curve is critical.
The sample code :
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.input.MouseEvent;
import javafx.scene.shape.QuadCurve;
import javafx.stage.Stage;
public class QuadCurveMouseHandling extends Application {
@Override
public void start(Stage stage) throws Exception {
QuadCurve curve = new QuadCurve();
curve.setStartX(10);
curve.setStartY(10);
curve.setControlX(50);
curve.setControlY(250);
curve.setEndX(300);
curve.setEndY(300);
curve.setStyle("-fx-stroke-width: 7;-fx-stroke: green;-fx-fill: red;");
curve.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
System.out.println("clicked");
}
});
stage.setScene(new Scene(new Group(curve), 320, 320));
stage.show();
}
public static void main(String[] args) {
launch();
}
}