At your event listener, you can dispatch the event to the parent component.
Being myEvent
the event handling function argument:
Component source=(Component)myEvent.getSource();
source.getParent().dispatchEvent(myEvent);
But this solution implies creating a new EventListener for each element to add.
So, you could create a single event handler and reuse it, adding it to all the chosen children, like this:
final Container parent=this; //we are a the parent container creation code
MouseListener myCommonListener=new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
parent.dispatchEvent(e);
}
@Override
public void mouseEntered(MouseEvent e) {
parent.dispatchEvent(e);
}
@Override
public void mouseExited(MouseEvent e) {
parent.dispatchEvent(e);
}
@Override
public void mousePressed(MouseEvent e) {
parent.dispatchEvent(e);
}
@Override
public void mouseReleased(MouseEvent e) {
parent.dispatchEvent(e);
}
};
JLabel label=new JLabel("This is the first Label");
label.addMouseListener(myCommonListener);
JLabel label2=new JLabel("This is the second Label");
label2.addMouseListener(myCommonListener);
//... and so on