2事件调度到底层节点

2事件调度到底层节点

本文介绍了JavaFX 2事件调度到底层节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有没有正确的方法来解决两个兄弟窗格之间的事件传播问题?例如,我们在StackPane中有2个窗格。

  StackPane p = new StackPane(); 
Region p1 = new Region();
Region p2 = new Region();
p.getChildren()。addAll(p1,p2);在此示例中,

p2捕获鼠标事件,即使事件未消耗,p1也无法对其进行响应



如果p2没有消费,是否有正确的方式将事件传播到p1?



setMouseTransparent not解决我的问题,因为我需要这两个孩子元素对鼠标的反应。



感谢建议。

解决方案

我的问题已部分解决。也许我不太正确地提出问题。
我写的应用程序像图形编辑器,并在stackpane上有工具层窗格,包括指南,网格,选择工具等,并且需要这个层的子层可以处理鼠标和窗格本身将对于鼠标事件是透明的。 / p>

问题是通过覆盖pickNode解决的,而不是在公共API中,但它的工作。
也许可以帮助某人。

  protected Node impl_pickNodeLocal(double localX,double localY){
if(containsBounds (localX,localY)){
ObservableList< Node> children = getChildren(); (int i = children.size() - 1; i> = 0; i--){
Node pick = children.get(i).impl_pickNode(localX,localY);

if(pick!= null)return pick;
}
// hack使窗格本身对鼠标
透明//如果(contains(localX,localY))返回此;
}
返回null;
}


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.

解决方案

My problem was partially solved. Maybe I not quite correctly formulate question.I write app like graphic-editor and have tools-layer panes on stackpane with guides, grid, selection-tools etc. and need that children of this layers can handle mouse and panes itself will be transparent for mouse events.

Problem was solved by override pickNode, not in public API, but it work.Maybe help somebody.

protected Node impl_pickNodeLocal(double localX, double localY) {
    if (containsBounds(localX, localY)) {
        ObservableList<Node> children = getChildren();
        for (int i = children.size()-1; i >= 0; i--) {
            Node picked = children.get(i).impl_pickNode(localX, localY);
            if (picked != null) return picked;
        }
        // hack to make pane itself transparent for mouse
        // if (contains(localX, localY)) return this;
    }
    return null;
}

这篇关于JavaFX 2事件调度到底层节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 13:00