Created
July 24, 2021 05:01
-
-
Save ruimo/92780146057d00abd65a9f8591042785 to your computer and use it in GitHub Desktop.
Mouse event is propagated to all of the children 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.application.Application; | |
import javafx.geometry.Pos; | |
import javafx.scene.Scene; | |
import javafx.scene.layout.StackPane; | |
import javafx.scene.layout.Pane; | |
import javafx.stage.Stage; | |
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(); | |
Pane pane1 = new Pane(); | |
pane0.onMouseMovedProperty().setValue(e -> { | |
System.err.println("Pane0 (" + e.getX() + ", " + e.getY() + ")"); | |
}); | |
// Only this event handler is called. | |
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