I have a situation where I have two child nodes in a container node (HBO) and Java Fx. When I pull the left child from the nodes to the right, I get many drag events in the left node, and in the end when I leave the mouse on the right node, I get a click event in my parents. Some codes are given below to replicate this situation.
What should I know: How do I stop parents who receive this click event? I have tried to do all event filters and event handlers on the left and right nodes consuming events, but I am unable to find exactly one (S) to stop the click event sent to parents. any idea?
Package testing; Import javafx.application.Application; Import javafx.scene.Scene; Import javafx.scene.control.Label; Import javafx.scene.layout.Background; Import javafx.scene.layout.BackgroundFill; Import javafx.scene.layout.HBox; Import javafx.scene.paint.color; Import javafx.stage.Stage; Enhances public class testdrags application {@ Override Public VoOdStart (Stage Primary Stage) throws an exception {string left head = "start dragging me \ n"; String drag starred = "start a drag; stay simple \ n"; Label Left = New Label (Left Head); Left.setOnDragDetected (e - & gt; {left.setText (left-hand + drag-start); e.consume ();}); Left.setOnMouseDragged (e -> {left.setText (leftHead + dragStarted + "mouse has been dragged:" + e.getSceneX + "," + e.getSceneY ()); e.consume (); }); Left.setOnMouse RealLed (E-> {left.setText (left-hand + "mouse released \ n"); e.consume ();}); String rightHead = "drag to me \ n"; Label correct = new label (right hand); Right.setOnMouseClicked (e-> {right.setText (right hand + "I clicked! \ N");}); Left.setPrefSize (400, 300); Right.setPrefSize (400, 300); Right.setBackground (new background (new backgroundfile (color .lIGHTPINK, empty, empty)); Left.setBackground (new background (new backgroundfile (light; zero, zero)); HBOX Hbox = New HBbox (left, right); Hbox.setOnMouseClicked (e -> click on built-in HBox on "right.setText (rightHead +" "+ System.currentTimeMillis (+ +" \ n ");}); PrimaryStage.setScene (new view (hbox)); primaryStage.show ();}}
< P> You can not prevent the event from being per-click, but (in
MouseEven T
) can be used (in this example HBox
) to differentiate between a click and drag.
Comments
Post a Comment