Created
June 25, 2015 10:15
-
-
Save TheItachiUchiha/66322bc3a998bae23e56 to your computer and use it in GitHub Desktop.
A small example which shows that MouseClick events are listened by both child and its container
This file contains hidden or 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
import javafx.application.Application; | |
import javafx.geometry.Pos; | |
import javafx.scene.Scene; | |
import javafx.scene.control.Label; | |
import javafx.scene.layout.StackPane; | |
import javafx.scene.layout.VBox; | |
import javafx.stage.Stage; | |
public class Main extends Application { | |
@Override | |
public void start(Stage primaryStage) throws Exception { | |
VBox fxmlContainer = new VBox(); | |
fxmlContainer.setStyle("-fx-background-color: ANTIQUEWHITE"); | |
fxmlContainer.getChildren().add(new Label("Click Anywhere!!")); | |
fxmlContainer.setAlignment(Pos.CENTER); | |
StackPane stackPane = new StackPane(fxmlContainer); | |
fxmlContainer.setOnMouseClicked(event -> System.out.println("You have clicked on VBox")); | |
stackPane.setOnMouseClicked(event -> System.out.println("You have clicked on StackPane")); | |
Scene scene = new Scene(stackPane, 150, 150); | |
primaryStage.setScene(scene); | |
primaryStage.show(); | |
} | |
public static void main(String[] args) { | |
launch(args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks for the help