Is it possible to get the name of the panel that a JLabel is added to? I added some JLabels to different JPanels, and I want to call different mouse events according to whic
If you don't know how deep down your label is in the hierarchy, there's some handy functions in SwingUtilities, for example: SwingUtilities.getAncestorOfClass(Class, Component)
An alternative to checking the name of the parent container in your labels could be to simply forward the event to the parent container instead and let the parent do the work. Depending on what you're trying to achieve, it could be useful to decouple the labels from the parents. Forwarding events can be done using Component.processEvent(AWTEvent).