Reputation: 1124
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)?
Upvotes: 0
Views: 292
Reputation: 82461
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
.)
Upvotes: 2