I’m puzzled with a strange mouse listener behavior.
First, I defined an interface :
public interface GeniusField {
public void setEdited(Boolean b);
public void addMouseListeners();
public void addKeyListeners();
public String getStringValue();
}
then, I implement this interface :
public class GeniusComboField extends JComboBox implements GeniusField {
public GeniusComboField() {
super();
//blabla
addMouseListeners();
addKeyListeners();
}
@Override
public void addMouseListeners() {
System.out.println("ADD LISTENTER");
this.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
System.out.println("mouse mouse");
}
});
}
}
And for some reason, nothing is triggered when I click on my combobox (but I get the “ADD LISTENER” output).
I don’t see what is happening.
Can someone help?
In Java Swing JComboBox don’t receive the mouse events. It’s the components within that do it. Try something like:
Then make your class implements MouseListener.
Or you can override the method to add object to your combobox and call your
addMouseListener()method. Like that each object will have a listener.