Created
July 24, 2021 05:46
-
-
Save ruimo/494d32d7771f8594d643838f4177ca45 to your computer and use it in GitHub Desktop.
How to propagate mouse event under more than one children Nodes of a StackPane.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package jfxsbox; | |
import javafx.event.EventHandler; | |
import javafx.application.Application; | |
import javafx.geometry.Pos; | |
import javafx.scene.Scene; | |
import javafx.scene.layout.StackPane; | |
import javafx.scene.layout.Pane; | |
import javafx.stage.Stage; | |
import javafx.scene.Node; | |
import javafx.scene.shape.Circle; | |
public class Main extends Application { | |
public static void main(String[] args) { | |
launch(args); | |
} | |
@Override | |
public void start(Stage stage) throws Exception{ | |
stage.setWidth(260); | |
stage.setHeight(130); | |
Pane pane0 = new Pane(); | |
pane0.pickOnBoundsProperty().setValue(false); | |
Pane pane1 = new Pane(); | |
pane1.pickOnBoundsProperty().setValue(false); | |
Circle c0 = new Circle(30, 30, 30); | |
Circle c1 = new Circle(100, 30, 30); | |
c0.onMouseMovedProperty().setValue(e -> { | |
System.err.println("c0 (" + e.getX() + ", " + e.getY() + ")"); | |
}); | |
c1.onMouseMovedProperty().setValue(e -> { | |
System.err.println("c1 (" + e.getX() + ", " + e.getY() + ")"); | |
}); | |
pane0.getChildren().add(c0); | |
pane1.getChildren().add(c1); | |
pane0.onMouseMovedProperty().setValue(e -> { | |
System.err.println("Pane0 (" + e.getX() + ", " + e.getY() + ")"); | |
}); | |
pane1.onMouseMovedProperty().setValue(e -> { | |
System.err.println("Pane1 (" + e.getX() + ", " + e.getY() + ")"); | |
}); | |
StackPane stackPane = new StackPane(); | |
stackPane.getChildren().add(pane0); | |
stackPane.getChildren().add(pane1); | |
stage.setScene(new Scene(stackPane)); | |
stage.show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment