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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 2840

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.
Consider Paul's rocket mass heater.
subject: Get a component from x / y coords
Similar Threads
JLayeredPane in JPanel?
Trouble Aligning JButtons (And setting width)
JtableHeader with two separate listeners, one for each component : classic label and extra checkbox
MouseEvent x,y relative to entire screen
hs teacher needs help - display swing components with coordinates