如何在“笔画”上检测鼠标点击QuadCurve的一部分? [英] How to detect MouseClick on the "stroke" part of a QuadCurve?
本文介绍了如何在“笔画”上检测鼠标点击QuadCurve的一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检测QuadCurve上的鼠标点击事件,但仅限于笔画部分。仅清除图像的绿色部分。
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.
示例代码:
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();
}
}
推荐答案
设置填充为null而不是颜色。
Set the fill to null rather than a color.
例如 -fx-fill:null;
=>如果没有填充,则无法点击它。
e.g. -fx-fill: null;
=> if the fill is not there, you can't click on it.
这篇关于如何在“笔画”上检测鼠标点击QuadCurve的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文