[英]JavaFX- getting the location of a click on a gridpane
I have created a JavaFX project that displays an image. 我创建了一个显示图像的JavaFX项目。 I have used a canvas in JavaFX to draw this image and display it on an anchor pane. 我使用JavaFX中的画布绘制此图像并将其显示在锚点窗格中。 I have put a gridpane on the top of the image and essentially what I need to do is when the user clicks on a specific box in the grid, find out where that click was made so I can store the coordinates in a text file. 我已经在图像的顶部放置了一个网格窗格,本质上我需要做的是,当用户单击网格中的特定框时,找出单击的位置,以便将坐标存储在文本文件中。
I was thinking of putting a button in each box but this will take a while, is there an easier way of achieving this using just the gridpane? 我当时想在每个框中放一个按钮,但这会花一些时间,是否有一种仅使用网格窗格实现此目的的简便方法? And how can the location/ coordinates of this click gained? 以及如何获得此点击的位置/坐标?
Thank you! 谢谢!
gridpane.addEventHandler(MouseEvent.MOUSE_CLICKED, e ->{
e.getX();
e.getY();
//And if applicable
e.getZ();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.