简体   繁体   English

在BorderPane中时不遵守ScalaFX / JavaFX Node.translateX / Y

[英]ScalaFX/JavaFX Node.translateX/Y not obeyed when inside BorderPane

I am drawing various Rectangle nodes that I want to be able to drag around the screen. 我正在绘制各种我希望能够在屏幕上拖动的矩形节点。

My code is currently this: 我的代码当前是这样的:

  stage = new Stage {
    scene = new Scene(1100, 700) {
      root = new BorderPane {
        center = new Group() {
          fill = Color(0.22, 0.22, 0.22, 1.0)
          children = List(
            new Rectangle with Draggable {
              x = 100.0
              y = 100.0
              width = 80.0
              height = 50.0
              arcWidth = 7.5
              arcHeight = 7.5
              fill = Color(0.15, 0.15, 0.15, 1.0)

              onMousePressed = (event: MouseEvent) => {
                draggablePerformPress(event)
              }

              onMouseDragged = (event: MouseEvent) => {
                draggablePerformDrag(event)
              }
            }
          )
        }
      }.delegate
    }
  }

The Draggable trait provides the draggablePerformPress() and draggablePerformDrag() methods, which essentially is where translateX and translateY are set. Draggable特征提供了draggablePerformPress()和draggablePerformDrag()方法,本质上是在其中设置了translateX和translateY的位置。

If I click and drag on the Rectangle node, it doesn't move. 如果我在“矩形”节点上单击并拖动,它不会移动。 However, if I remove the BorderPane and make the Group object the Scene's root, then dragging works. 但是,如果删除BorderPane并将Group对象作为场景的根,则可以进行拖动。 I've confirmed that the onMouse events are being triggered, so it must be that for some reason BorderPane is overriding translateX/Y... I just don't know why, and I don't know how to prevent that from happening. 我已经确认onMouse事件已被触发,因此一定是由于某种原因BorderPane覆盖了translationX / Y ...我只是不知道为什么,而且我也不知道如何防止这种情况的发生。

I solved the problem. 我解决了问题。 By changing the Group to a Pane, the code now works. 通过将组更改为窗格,代码即可正常工作。 However, I am still unsure why Group cannot be used in this instance (but it could be without the BorderPane as its parent). 但是,我仍然不确定为什么不能在这种情况下使用Group(但是在没有BorderPane作为其父对象的情况下可以使用Group)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM