1

I am looking for a way to draw a node on top of the neighbouring ones in a HBox. Default behaviour means it is drawn on top of the previous one, but that also means the next one is drawn on top of it. For other containers, one could use the Node.toFront(), but changing the position of the node in the list containing a HBox's children also changes the actual position in the HBox, which is unwanted behaviour in my case. I appreciate any help, thank you.

EDIT: The overlapping occurs when applying a DropShadow effect on an Ellipse and wrapping them in a StackPane along with a Text. It looks like the effect has a weird interaction with the HBox, as it works as intended without it. After adding the effect, it allocates more horizontal space for the ellipse, but not enough to cover the margins of the effect. Also, when clicking anywhere in the whole right half of the black rectangle, the mouse click is dispatched to the stackPane event handler, not to the rectangle's.

This happens

4

1 回答 1

0

在 VBox 和 HBox 中,Node.toFront() 和 Node.toBack() 函数会改变布局,因此它们不可用。如果您使用的是 JavaFX 9+,您可以使用 viewOrder 命令更改其父节点中节点的渲染顺序:

Node.getViewOrder()
Node.setViewOrder()

viewOrder 的默认值为 0,因此将其设置为 -1 会将其呈现在所有其他之上。您可以对其进行自定义以获取特定订单。它还有一个 CSS 属性 -fx-view-order。

于 2022-02-21T20:09:17.350 回答