Yes, the title looks like the set up of a joke and yet it isn't.
The problem
I am writing a program using JavaFX. I add some drawings in a Pane (standard Line, Circle, Rectangle, and so on from javafx.scene.shape
). I have set a onMouseEnter()
on some circles to change their color. That works great, except when I place a line like in the image below:
The circle A
changes color normally until I add the line B
. When I hover the circle A
then, nothing happens.
I figured out by testing that there was a problem when the circle was in the bounding box of the line (if the circle is halfway in the bounding box, the half that is out behaves correctly and the one inside doesn't).
Is it a normal behavious? What can I do to prevent it?
Partial code
In ConnectorWidget.java:
Circle circle = new Circle(...);
circle.setOnMouseEntered(event -> circle.setFill(Color.RED));
circle.setOnMouseExited(event -> circle.setFill(Color.WHITE));
getChildren().add(circle);
In TransistorWidget.java:
ConnectorWidget base = new ConnectorWidget(...);
getChildren().add(base);
In WireWidget:
Line line = new Line(...);
getChildren().add(line);
A new TransisorWidget
can be added to the main pane on click.
A new WireWidget
can be created in the main pane after a click on a ConnectorWidget
followed by a click on another ConnectorWidget
.
The rest of the code can be found on GitHub (permalink to the last commit I have when asking the question).
NOTE: To run the code from GitHub, you need this library.