Reputation: 890
i have sth. like:
Path path= new Path();
MoveTo moveTo = new MoveTo();
moveTo.setX(390);
moveTo.setY(165);
LineTo lineTo = new LineTo();
lineTo.setX(235);
lineTo.setY(130);
path.getElements().add(moveTo);
path.getElements().add(lineTo);
path.setStrokeWidth(5);
path.setStroke(Color.BLACK);
field.getChildren().add(path);
Now I want to add a Listener to the Line I drew - I thought about 2 possibilities:
first: I can add somehow a Listener to lineTo
second: I can add somehow a Listener to the Area of the Line (a Hitbox from (390,165) to (235,130) with the width of 5px)
Can you tell me how I could do this? I am new with JavaFX and I got no idea. In the end it should be possible to click on a line to change the color.
Upvotes: 1
Views: 305
Reputation: 34528
LineTo
is only a logical element. The actual graphical entity is Path
which can be enhanced with listeners:
path.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent t) {
path.setStroke(Color.RED);
}
});
Upvotes: 2