Reputation: 592
removeEventHandler()
is ok, but what if I don't keep reference on handler ?
Can I remove any event handler(filter) by event type or even all handlers from my JavaFX
. scene.Node
instance? I guess that somewhere a list of handlers existed, and I can traverse it, and remove what I want.
Upvotes: 11
Views: 10664
Reputation: 444
I came across this question while looking for how to create event handlers that remove themselves. The answer to my question was here, I don't know if it will help you. javafx have an eventfilter remove itself
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
Upvotes: 4
Reputation: 159376
Can I remove any event handler(filter) by event type or even all handlers from my javafx.scene.Node instance?
I don't think you can remove an event handler or filter which you didn't have a reference to originally. You can add extra event filters to filter out processing for events by type or you can set your own event dispatcher on the node and have your custom dispatcher only forward the events you want to the node's standard event dispatcher.
I guess that somewhere a list of handlers existed, and I can traverse it, and remove what I want.
Yes, but that is buried within the private implementation of the Node, so you probably don't want to hack the private Node code to do that.
Upvotes: 5