944,039 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 2515
  • Java RSS
Dec 1st, 2004
0

manipulating graphs in a GUI

Expand Post »
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!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
matt_5104 is offline Offline
15 posts
since Nov 2004
Dec 1st, 2004
0

Re: manipulating graphs in a GUI

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).
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: How to invoke array varibles to another main method
Next Thread in Java Forum Timeline: Syntax Analyser and General Java Help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC