Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Is there a correct way to solve the problem with event propagation between two sibling panes?

For example we have StackPane with 2 panes inside.

StackPane p = new StackPane();
Region p1 = new Region();
Region p2 = new Region();
p.getChildren().addAll(p1, p2);

p2 in this example capture mouse events and p1 can't react on it even if event is not consumed.

Is there a correct way to propagate event to p1 if it not consumed by p2?

setMouseTransparent not solve my problem because I need that both children elements react on mouse.

Thanks for advise.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
535 views
Welcome To Ask or Share your Answers For Others

1 Answer

By default events will just propagate up the heirarchy and terminate at the root. There are a few approaches you could take to solve your problem.

  1. Create your own event instance. Add an event handler to both regions that triggers your shared event instance. Add any event handling code you want to be common across regions to the shared instance. This is the approach I would take from the description you've given.
  2. Catch all events at the root and, instead of just letting them die, create a global event register that everyone can register for.
  3. Create an event handler at the first region and catches events and redispatches them at the second region (using buildEventDispatchChain.dispatchEvent). Then do the same on the other side.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...