Question

I have the following code to listen for mouseclicks, but it appears to not always fire.

nameList.addChangeListener( new MouseAdapter(){
    @Override
    public void mouseClicked(MouseEvent me) {
        nameListUpdated();
    }
} );

nameListUpdated() will run some of the times, but for whatever reason it seems that it will not run on every click like i want. Does anyone know why? Or is there more information to find the problem?

Was it helpful?

Solution

I would suggest instead of using method addChangeListener

 nameList.addChangeListener( new MouseAdapter(){
 @Override
 public void mouseClicked(MouseEvent me) {
     nameListUpdated();
 }
} );

use method for adding mouse listener addMouseListener

 nameList.addMouseListener( new MouseAdapter(){
 @Override
 public void mouseClicked(MouseEvent me) {
     nameListUpdated();
 }
} );

OTHER TIPS

Try using mousePressed instead. It will fire an event when you press mousebutton without waiting until you release it. In most cases it does the trick.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top