Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Post Two Overlapping Components

    Hi There.

    I hava this question that how can i find out that two components placed in JFrame ( eg :: x1, y1 for the first component and x2, y2 for the second one with different sizes ) are ovelapping.

    I tried arrays with width and height of the JFrame and fill with '1' for occupied pixels but it takes a long time. and i tried method findComponent( int x, int y ) but all i did the method responsed null or i dont know how to do it?

    PLEASE HELP

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    Use a layout manager. The layout manager makes sure that components don't overlap.

  3. #3
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default

    No. I want objects to overlap then i get the result whether if they are overlapping or not. You know, it's kinda pacman thing.

  4. #4
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    Maybe you can use the contains method:

    Java Code:
    if (component1.contains( component2.getLocation() )
     ...

  5. #5
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Post

    I dont know why, but it didn't work. for the record, i put my pacman icons in JLabels.

Similar Threads

  1. frame overlapping
    By sameerk in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 08-19-2010, 08:45 AM
  2. Overlapping JLabels
    By techbossmb in forum AWT / Swing
    Replies: 3
    Last Post: 09-21-2009, 04:21 PM
  3. Help with overlapping JPanels
    By xcallmejudasx in forum New To Java
    Replies: 2
    Last Post: 03-09-2009, 11:19 PM
  4. Overlapping Components using Netbeans GUI Interface
    By hitmen in forum Java Applets
    Replies: 3
    Last Post: 03-06-2009, 06:33 AM
  5. overlapping forms
    By keerthi_y19 in forum New To Java
    Replies: 4
    Last Post: 08-26-2008, 11:30 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
  •