As from James_D code posted here How to progate an event to a children using JavaFx2
I am interested in how to attach an event to group made of Line and Anchor, or at line only in order to intercept the delete key keyboard press to remove the whole group.
yes I am aware of this and I have tried it but I can't add the event to the group.
The example does not work when I try to add the event to the group created with
group.getChildren().addAll(line, startAnchor, endAnchor);
Keyboard events are only "heard" by the Node that has keyboard focus - so you would need some way for your Group/Line to have keyboard focus. Try registering a mouse handler with the line which requests keyboard focus when the user clicks on the line.
Your code adds a handler for KeyEvents to the line; but the line will not generate any key events unless it has the keyboard focus.
You need to arrange for the particular line you want to delete to have the keyboard focus when the delete key is pressed. Try calling
when, for example, you add a new line. Then the delete key should delete the most recently added line, as long as keyboard focus has not moved since it was added.