JavaFX 圆角碰撞箱

JavaFX rounded corners hitbox

在我的程序中,我使用 css 设置了我的按钮样式。我正在使用“-fx-background-radius”来圆角,并注意到当我将鼠标悬停在原来的角上时,它允许我单击按钮。我只是想知道是否有办法使按钮的 'hit-box' 与您看到的相匹配。

谢谢。

pickOnBounds 属性

Defines how the picking computation is done for this node when triggered by a MouseEvent or a contains function call. If pickOnBounds is true, then picking is computed by intersecting with the bounds of this node, else picking is computed by intersecting with the geometric shape of this node.

"bounds" 本质上是包含节点(在本例中为按钮)的矩形区域。 "geometric shape" 说明了节点的实际呈现方式。

所以你只需要在按钮上调用 setPickOnBounds(false)