File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Get a component from x / y coords Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Get a component from x / y coords" Watch "Get a component from x / y coords" New topic

Get a component from x / y coords

Trisha Murphy

Joined: Sep 19, 2002
Posts: 13
Hi I have a JPanel with about 4 components in it
I can get the position of a component using GridBagConstraints.
is there anyway I can get the instance of the component using the coordinates?
I tried using getComponentAt() but that just returns the whole JPanel.
myPanel.getComponentAt(x, y)
What I'm trying to do is get the component that is next to the compnenet I have selected.
Greg Charles

Joined: Oct 01, 2001
Posts: 2968

Try findComponentAt(x,y). I'm vague on how these methods differ, but the "find" version definitely claims to drill down through containers to find the visible component. The "get" version doesn't really specify what it does, although I suppose we could look at the code.
I agree. Here's the link:
subject: Get a component from x / y coords
It's not a secret anymore!