Background
I am trying to build a image gallery based on the description here.
I have a StackPane
, with ScrollPane
Instead of placing the AnchorPane
and ScrollPane
in a StackPane
, try using the AnchorPane
as the root of this structure. Add the ScrollPane
to it first with appropriate anchors and then add the buttons. That way the buttons will still be on top, but there will be nothing interfering with the mouse events on the content of the scroll pane.
ScrollPane scrollPane = new ScrollPane();
scrollPane.setContent(...);
// scrollPane fills entire anchor pane:
AnchorPane.setLeftAnchor(scrollPane, 0.0);
AnchorPane.setRightAnchor(scrollPane, 0.0);
AnchorPane.setTopAnchor(scrollPane, 0.0);
AnchorPane.setBottomAnchor(scrollPane, 0.0);
Button button1 = new Button(...);
Button button2 = new Button(...);
// button1 in top left:
AnchorPane.setTopAnchor(button1, 0.0);
AnchorPane.setLeftAnchor(button1, 0.0);
// button2 in top right:
AnchorPane.setTopAnchor(button2, 0.0);
AnchorPane.setRightAnchor(button2, 0.0);
AnchorPane anchorPane = new AnchorPane();
anchorPane.getChildren().addAll(scrollPane, button1, button2);