是否有正确的方法来解决两个同级窗格之间的事件传播问题?
Is there a correct way to solve the problem with event propagation between two sibling panes?
例如,我们有内部有 2 个窗格的 StackPane.
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 捕获鼠标事件,即使未消耗事件,p1 也无法对其做出反应.
p2 in this example capture mouse events and p1 can't react on it even if event is not consumed.
如果事件不被 p2 消费,是否有正确的方法将事件传播到 p1?
Is there a correct way to propagate event to p1 if it not consumed by p2?
setMouseTransparent 不能解决我的问题,因为我需要两个子元素都对鼠标做出反应.
setMouseTransparent not solve my problem because I need that both children elements react on mouse.
感谢您的建议.
我的问题部分解决了.也许我不太正确地提出问题.我编写了图形编辑器之类的应用程序,并在带有指南、网格、选择工具等的 stackpane 上有工具层窗格,并且需要该层的子层可以处理鼠标,并且窗格本身对于鼠标事件是透明的.
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.
问题已通过覆盖 pickNode 解决,而不是在公共 API 中,但它可以工作.也许可以帮助某人.
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 事件分派到底层节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何检测 32 位 int 上的整数溢出?How can I detect integer overflow on 32 bits int?(如何检测 32 位 int 上的整数溢出?)
return 语句之前的局部变量,这有关系吗?Local variables before return statements, does it matter?(return 语句之前的局部变量,这有关系吗?)
如何将整数转换为整数?How to convert Integer to int?(如何将整数转换为整数?)
如何在给定范围内创建一个随机打乱数字的 intHow do I create an int array with randomly shuffled numbers in a given range(如何在给定范围内创建一个随机打乱数字的 int 数组)
java的行为不一致==Inconsistent behavior on java#39;s ==(java的行为不一致==)
为什么 Java 能够将 0xff000000 存储为 int?Why is Java able to store 0xff000000 as an int?(为什么 Java 能够将 0xff000000 存储为 int?)