Hi, I'm creating a GUI in which users are required to interact with graphs. I have a jFrame on which I have put a jLabel and used this label to import a JPEG of a graph (i.e it's an icon). My problem is that the user needs to pick a point on the graph, and from that two coordinates will be obtained. These coordinates obviously need to corespond with the axes on the graph. How can I convert the pixel coordinates of the jLabel that the mouseClicked event will give me into coordinates that correspond to the JPEG graph? Any help is great appreciated!

12 Years
Discussion Span
Last Post by jwenting

Determine the top corner of the component you use to display the image and use those as an offset.
For example if the image is displayed from 100,100 on your application window and your mouse coordinates are 150,150 your coordinates in the image would be 50,50 (or was that 49,49 ...).

Mind this is just an example, I haven't checked if the coordinates in either case are calculated from the top left corner of the application window (some libraries have a tendency to calculate from the bottom right corner in which case you need the window size as well to calculate another offset to determine the top left corner).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.