I am using a GridPane
with several cells. I add Label
dynamically to each cell. I need each Label's position. My code is like below:
@FXML
GridPane graphHolder;
Label label = new Label("A");
label.setWrapText(true);
graphHolder.add(label, 1, 0);
javafx.geometry.Point2D point1 = label.localToScreen(0.0, 0.0);
System.out.println(point1);
Label label2 = new Label("B");
label2.setWrapText(true);
graphHolder.add(label2, 3, 1);
javafx.geometry.Point2D point2 = label2.localToScreen(0.0, 0.0);
System.out.println(point2);
This point1
and point2
are returning same position Point2D [x = 834.0000009536743, y = 158.99999225139618]
though they are in different cells. How can I get exact positions of those two Labels? Please help.