Issue
I just made Button which has HBox inside the button. And when i click inside button, the outer button is clicked too. I just want to make one button can be clicked at once. How can i handle this Buttons?
This is JavaFX controller code.
Button b = new Button();
Button front = new Button("Stop");
front.setPrefWidth(50);
front.setOnAction((e) -> {
System.out.println("front click");
});
HBox h = new HBox();
h.getChildren().addAll(front);
b.setGraphic(h);
b.setOnAction((e) -> {
System.out.println("back click");
});
and when i run this code and when i click front button the result is
front click
back click
front click
back click
front click
back click
front click
back click
front click
back click
front click
back click
when i click front button, back button is clicked, too. how can i handle this?
Solution
Event Consume
should work.
front.setOnAction((e) -> {
System.out.println("front click");
e.consume();
});
Answered By - Sedrick