I want a line to bind from the mouse position while mouse is pressed.
(我希望在按下鼠标时从鼠标位置绑定一条线。)
Here is what i try : (这是我尝试的:)
scene.setOnMousePressed(e ->{
Line line = new Line();
root.getChildren().add(line);
DoubleProperty x = new SimpleDoubleProperty(e.getX());
DoubleProperty y = new SimpleDoubleProperty(e.getY());
line.setStartX(0.0f);
line.setStartY(0.0f);
line.endXProperty().bind(x);
line.endYProperty().bind(y);
scene.setOnMouseReleased(eMoved ->{
root.getChildren().remove(line);
});
});
But the line is not moving.
(但是线没有动。)
I know i could do something like that : (我知道我可以做这样的事情:)
Line line = new Line();
root.getChildren().add(line);
line.setStartX(0.0f);
line.setStartY(0.0f);
scene.setOnMouseMoved(e ->{
line.setEndX(e.getX());
line.setEndY(e.getY());
});
But there is a little delay when moving the mouse (maybe this the best i can have, i don't know).
(但是移动鼠标时会有一点延迟(也许这是我所能拥有的最好的,我不知道)。)
Thanks. (谢谢。)
ask by perwhite translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…