I have a composite tree. I’ve drawn this tree to a JPanel width Graphics object via overriding paintComponent(Graphics gr). My problem is: how can I access which component is clicked?
I only figured out trivial and bad solutions, so that’s why I turn to you. Thanks in advance!
The shapes you have drawn, you need to store.
When you receive a Mouse clicked event:
you will have x and y from
You can then traverse your shapes, and see if a Shape contains the point above. From the Javadoc of Shape: