OK so I’ve got a JPanel with a GridLayout. Each cell of the grid then contains another JPanel.
What I’d like to be able to do is have a listener on the “underneath” JPanel which then tells me which of the “overlayed” JPanels was clicked – so I can react to it and the surrounding ones, without making the covering JPanels aware of their position (they change!!)
Is there a way of doing this – similar to Determine clicked JPanel component in the MouseListener. Event handling but I couldn’t find a way of grabbing the component on top.
I could probably grab the co-oridnates and work it out using that info – but I’d rather not!!
Any help/pointers/tips would be appreciated 😀
Do the same thing but use
getParent()on the source. Or you can search up the hierarchy if it is deeper, even some helper methods for that:javax.swing.SwingUtilities.getAncestorOfClassandgetAncestorNamed