JavaFX 中的 Z 顺序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2988196/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 15:18:08  来源:igfitidea点击:

Z-Order in JavaFX

javajavafxz-ordervbox

提问by Scaraffe

How do I set Z-order for VBoxin JavaFX?

如何VBox在 JavaFX 中设置 Z 顺序?

采纳答案by PhiLho

Z-order in JavaFX is actually the order in the scenegraph, eg. in the content sequence of the scene (then in the contents of the groups, containers, etc.).

JavaFX 中的 Z 顺序实际上是场景图中的顺序,例如。在场景的内容序列中(然后在组、容器等的内容中)。

All nodes have also toFront() and toBack() functions to help changing this order. For finer control, you have to remove nodes from one place and insert it higher or lower in the sequence.

所有节点还具有 toFront() 和 toBack() 函数来帮助更改此顺序。为了更好地控制,您必须从一个地方删除节点并将其插入序列中的更高或更低的位置。

回答by tombrus

With the toFront() and toBack() functions you can indeed influence the z-order, but be aware that this also influences the layout. The HBox and VBox for instance also use the sequence of children to do the layout and moving something to the front will also move it to the end of the [HV]Box. This might not be what you are looking for.

使用 toFront() 和 toBack() 函数,您确实可以影响 z 顺序,但请注意,这也会影响布局。例如,HBox 和 VBox 也使用子项序列来进行布局,将某些东西移到前面也会将其移到 [HV]Box 的末尾。这可能不是您要找的。

I was looking for a way to do an animation with the animated Node on top of all others, without messing up the layout. There seems to be no way to do that because the z-order and layout order are both taken from the child-order.

我一直在寻找一种方法,在不弄乱布局的情况下,将动画节点放在所有其他节点之上。似乎没有办法做到这一点,因为 z-order 和 layout order 都是从 child-order 中获取的。

回答by Slaw

While the other answers are still correct, JavaFX 9 added a way to manipulate the Z-order without modifying the children list. This is done with the Node.viewOrderproperty.

虽然其他答案仍然正确,但 JavaFX 9 添加了一种无需修改子列表即可操作 Z 顺序的方法。这是通过Node.viewOrder属性完成的。

Javadoc:

Javadoc:

Defines the rendering and picking order of this Nodewithin its parent.

This property is used to alter the rendering and picking order of a node within its parent without reordering the parent's childrenlist. For example, this can be used as a more efficient way to implement transparency sorting. To do this, an application can assign the viewOrdervalue of each node to the computed distance between that node and the viewer.

The parent will traverse its childrenin decreasing viewOrderorder. This means that a child with a lower viewOrderwill be in front of a child with a higher viewOrder. If two children have the same viewOrder, the parent will traverse them in the order they appear in the parent's childrenlist.

However, viewOrderdoes not alter the layout and focus traversal order of this Nodewithin its parent. A parent always traverses its childrenlist in order when doing layout or focus traversal.

Default value:

0.0

Since:

9

定义 thisNode在其父级中的渲染和拾取顺序。

此属性用于更改其父节点内节点的渲染和选取顺序,而无需重新排序父节点的children列表。例如,这可以用作实现透明度排序的更有效方法。为此,应用程序可以将viewOrder每个节点的值分配给该节点与查看器之间的计算距离。

父级将按children降序遍历它viewOrder。这意味着一个较低的孩子viewOrder将在一个较高的孩子面前viewOrder。如果两个孩子有相同的viewOrder,则父母会按照他们在父母children列表中出现的顺序遍历他们。

但是,viewOrder不会改变它Node在其父级中的布局和焦点遍历顺序。children在进行布局或焦点遍历时,父级总是按顺序遍历其列表。

默认值:

0.0

自从:

9