954,536 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

manipulating graphs in a GUI

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!

matt_5104
Newbie Poster
15 posts since Nov 2004
Reputation Points: 10
Solved Threads: 0
 

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).

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You