Handle mouse event anywhere with JavaFX
问题 I have a JavaFX application, and I would like to add an event handler for a mouse click anywhere within the scene. The following approach works ok, but not exactly in the way I want to. Here is a sample to illustrate the problem: public void start(Stage primaryStage) { root = new AnchorPane(); scene = new Scene(root,500,200); scene.setOnMousePressed(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { System.out.println("mouse click detected! "+event.getSource());