Вопрос

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?

Это было полезно?

Решение

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();
 }
} );

Другие советы

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top