Home » Java » Java/JavaFX – using removeEventFilter outside the method it was created in

Java/JavaFX – using removeEventFilter outside the method it was created in

Posted by: admin July 15, 2018 Leave a comment

Questions:

I have the following method:

public void add() {
    someObject.addEventFilter(MouseEvent.MOUSE_EXITED, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent mouseEvent) {
           ...
        }
    });
}

It makes my someObject do some magic tricks when I am no longer hovering it (MOUSE_EXITED). I want to remove this EventFilter now during the program with my remove method:

public void remove() {
    someObject.removeEventFilter(MouseEvent.MOUSE_EXITED, andWhatDoITypeHere);
}

My question is, how do I refer or point to the EventHandler < ? super T >, which is the second argument? Is it still possible to do it since I didn’t give it any name or reference, I just made a new EventHandler outside my remove method originally?

Thank you!

Answers: