override addMouseListener?
Hi,
I have a JPanel with a number of child controls. This JPanel is intended for use in a larger JFrame which has several other components, such as JFileChooser. I want the JFrame to know in which component the user is clicking.
If I add mouse listeners for the JFileChooser, it reports all clicks to the JFrame perfectly. However, doing the same for my JPanel only reports clicks for the JPanel itself, no clicks on the JPanel's child components report clicks to the JFrame. (i.e. if there is a button in the JPanel, clicks on that button are not reported to the JFrame. Only clicks to the grey spaces in the JPanel are reported)
This is the code I use in the JFrame:
myJPanel.addMouseListener(new MouseListener(){
publicvoid mouseClicked(MouseEvent evt){
//do something with click info
}
I've tried overriding the JPanel's addMouseListener, but it doesn't work. If I use the code:
@Override
publicvoid addMouseListener(MouseListener l){
super.addMouseListener(l);
}
It works exactly as before (obviously). But If I try adding any useful code, such as below, then all listener functions are lost - no clicks to the JPanel or its child components are reported)
@Override
publicvoid addMouseListener(MouseListener l){
super.addMouseListener(l);
MouseListener[] ml = jButton_in_JPanel.getMouseListeners();
for(int i = 0; i < ml.length; i++){
super.addMouseListener(ml[i]);
}
}
What am I doing wrong?

