当前位置: 动力学知识库 > 问答 > 编程问答 >

java - JavaFX: Drag and Drop absolute positioning

问题描述:

I implemented the drag and drop ImageView feature in JavaFX. The issue which I encountered is that when ImageView is dropped on the StackPane, it gets aligned to the top left corner. Is there a way to make the ImageView appear in the exact location where it was dropped (absolute positioning)?

网友答案:

Assuming you have set the alignment property of the StackPane or the ImageView to TOP_LEFT you can set the margin to position the node:

StrackPane pane = ...
...
ImageView iv = ...
...
double posX = ...
double posY = ...
StackPane.setMargin(iv, new Insets(posY, 0, 0, posX));
pane.getChildren().add(iv);

However since you seem to look for absolute positioning of children, a Pane seems to be the more appropriate layout. (The layoutX and layoutY properties of the children are not ignored for Pane.)

分享给朋友:
您可能感兴趣的文章:
随机阅读: