简体   繁体   中英

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.

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. 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.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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