JavaFX Delete all event handlers (filters)

removeEventHandler() fine, but what if I don't reference the handler?

Is it possible to remove an event handler (filter) by event type or even all handlers from my JavaFX . scene.Node instance? I assume that somewhere there was a list of handlers, and I can traverse it and delete what I want.

+7
source share
2 answers

I came across this question looking for ways to create event handlers that delete themselves. The answer to my question was here, I do not know if this will help you. javafx has an eventfilter filter

Here is an example

 EventHandler<MouseEvent> object_clicked=new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { // on click actions here my_node.removeEventFilter(MouseEvent.MOUSE_CLICKED, this); // at the bottom } }; my_node.addEventFilter(MouseEvent.MOUSE_CLICKED, object_clicked); // add the eventhandler to the node 
+3
source

Is it possible to remove an event handler (filter) by event type or even all handlers from my javafx.scene.Node instance?

I do not think that you can remove the event handler or filter with which you did not have a link to the original. You can add additional event filters to filter event processing by type, or install your own event dispatcher on node , and your custom dispatcher redirects only the events that you want to send to the node event dispatcher.

I assume that somewhere there was a list of handlers, and I can traverse it and delete what I want.

Yes, but this is buried in a private node implementation , so you probably won't want to crack a closed node for this.

+2
source

All Articles