Skip to content

Instantly share code, notes, and snippets.

@TheItachiUchiha
Created June 25, 2015 10:15
Show Gist options
  • Save TheItachiUchiha/66322bc3a998bae23e56 to your computer and use it in GitHub Desktop.
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
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);
}
}
@ldesperrois
Copy link

thanks for the help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment