如何在JLabel中获取图像的X,Y坐标 [英] How to get X,Y coordinates of an image in a JLabel

查看:353
本文介绍了如何在JLabel中获取图像的X,Y坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将地图图像放置为JLabel的图标. 我正在使用以下代码来获取单击鼠标的位置的X,Y坐标. 我已将此代码放在JLabel的MouseClick事件中.

I have an image of a map placed as the icon of a JLabel. I am using following code to get the X,Y coordinates of the location where the mouse is clicked. I have put this code in the MouseClick event of the JLabel.

Point point = MouseInfo.getPointerInfo().getLocation();

double X = point.getX();
double Y = point.getY();

,但是坐标取决于JFrame表单的位置.如果移动表格,则坐标会更改.

but the coordinates depend on the location of the JFrame form. If the form is moved the coordinates change.

反正我可以冻结JFrame吗? 或者 无论如何,我可以将图像的一个角设为0,0并获得相对于该角的其他坐标吗? (这样我就可以计算出实际坐标)

Is there anyway I can freeze the JFrame? Or Is there anyway I can get a corner of the image as 0,0 and get the other coordinates relative to that? (So I can calculate the actual coordinates)

推荐答案

查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆