• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get a component from x / y coords

 
Trisha Murphy
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 2993
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic