event.preventDefault() vs. return false

When I want to prevent other event handlers from executing after a certain event is fired, I can use one of two techniques. I’ll use jQuery in the examples, but this applies to plain-JS as well: 1. event.preventDefault() $(‘a’).click(function (e) { // custom handling here e.preventDefault(); }); 2. return false $(‘a’).click(function () { // custom … Read more

Handle mouse event anywhere with JavaFX

You can add an event filter to the scene with addEventFilter(). This will be called before the event is consumed by any child controls. Here’s what the code for the event filter looks like. scene.addEventFilter(MouseEvent.MOUSE_PRESSED, new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent mouseEvent) { System.out.println(“mouse click detected! ” + mouseEvent.getSource()); } });