Results 1 to 4 of 4
  1. #1
    Cleite is offline Member
    Join Date
    Apr 2009
    Posts
    6
    Rep Power
    0

    Default [SOLVED] Coordinates container --> in parent container.

    I have a listener on each of many small panels inside a big one. Then, when an event occurs, the Event object has stored coordinates relative to the small panel that invoked the event.

    Is there a way to find the coordinades of the event relative to the big parent panel? Or do I have to use screen coordinates?

  2. #2
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    You can do a bit of maths concerning the event coords and the panel's getBounds(). If the listeners are all very similar then it might make more sense to have one listener in the parent instead.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  3. #3
    Cleite is offline Member
    Join Date
    Apr 2009
    Posts
    6
    Rep Power
    0

    Default

    Yeah, that worked. Added
    Java Code:
    	    
    Rectangle bounds = ((JPanel) e.getSource()).getBounds();
    Point corner = bounds.getLocation();
    e.translatePoint((int) corner.getX(), (int) corner.getY());
    before using e.getPoint(). It ain't pretty, but it works splendid, thanks again.

  4. #4
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    or SwingUtilities.convertMouseEvent()
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

Similar Threads

  1. Applet as container .
    By pawankumarom in forum Java Applets
    Replies: 5
    Last Post: 04-23-2009, 07:17 AM
  2. AWT can we make a Tabbed container?
    By Panchitopro in forum AWT / Swing
    Replies: 0
    Last Post: 05-15-2008, 11:31 PM
  3. Container Managed Persistence
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-27-2007, 11:16 AM
  4. Butterfly Container 1.9.9-beta
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 11-17-2007, 03:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •