I'm ready to pull my hair out over this. I'm working on game GUI interface which has a map consisting of a grid of cells.
The grid of cells is composed of a StackPane and then several layers inside consisting of either ImageViews or Shapes etc.
The whole thing is contained in a GridPane, which comprises the center element of a BorderPane;
I can't add a mouse event to the underlying scene because then all the nodes get it -> no good. I need to highlight the nodes under the mouse.
Here's the code to create the stack:
private void initializePanes() {
myParent = new StackPane();
myObjectLayer = new StackPane();
myOverlayLayer = new StackPane();
myParent.getChildren().addAll(myObjectLayer, myOverlayLayer);
myParent.getStylesheets().add(myConfig.getString("StyleSheet"));
}
and Here's the code to set an EventHandler -> nothing works or registers. I've tried EventFilters too - no dice, not unless I write to the underlying scene, which is a No-Go.
private void initializeHandlers() {
myParent.addEventHandler(MouseEvent.ANY, (e) -> System.out.println("I'm responding"));
}
Help will be appreciated!
EDIT: here's the issue, The overall application is laid out as so:
BorderPane: Center -> StackPane Within that stackpane I have a ScrollPane, which contains a GridPane, which contains the cells (which I posted code for above).
I'm somewhat new to JavaFX so maybe this isn't a good way to do this. But for some reason, mouse events do not make it past the underlying stackpane -> i.e. they get absorbed by the center panel of the borderpane. I cannot add event handlers to the scroll pane, the grid pane, or any of the cells within the gridpane.
myObjectLayerandmyOverlayLayermouse transparent (setMouseTransparent(true)), or you could try registering the mouse handler withmyOverlayLayerinstead ofmyParent. But again, I have no idea if these will work. - James_D