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
Z-Order in JavaFX
提问by Scaraffe
How do I set Z-order for VBox
in 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.viewOrder
property.
虽然其他答案仍然正确,但 JavaFX 9 添加了一种无需修改子列表即可操作 Z 顺序的方法。这是通过Node.viewOrder
属性完成的。
Javadoc:
Javadoc:
Defines the rendering and picking order of this
Node
within its parent.This property is used to alter the rendering and picking order of a node within its parent without reordering the parent's
children
list. For example, this can be used as a more efficient way to implement transparency sorting. To do this, an application can assign theviewOrder
value of each node to the computed distance between that node and the viewer.The parent will traverse its
children
in decreasingviewOrder
order. This means that a child with a lowerviewOrder
will be in front of a child with a higherviewOrder
. If two children have the sameviewOrder
, the parent will traverse them in the order they appear in the parent'schildren
list.However,
viewOrder
does not alter the layout and focus traversal order of thisNode
within its parent. A parent always traverses itschildren
list in order when doing layout or focus traversal.Default value:
0.0
Since:
9
定义 this
Node
在其父级中的渲染和拾取顺序。此属性用于更改其父节点内节点的渲染和选取顺序,而无需重新排序父节点的
children
列表。例如,这可以用作实现透明度排序的更有效方法。为此,应用程序可以将viewOrder
每个节点的值分配给该节点与查看器之间的计算距离。父级将按
children
降序遍历它viewOrder
。这意味着一个较低的孩子viewOrder
将在一个较高的孩子面前viewOrder
。如果两个孩子有相同的viewOrder
,则父母会按照他们在父母children
列表中出现的顺序遍历他们。但是,
viewOrder
不会改变它Node
在其父级中的布局和焦点遍历顺序。children
在进行布局或焦点遍历时,父级总是按顺序遍历其列表。默认值:
0.0
自从:
9